Langage c: tableau
Résolu
julie
-
lami20j Messages postés 21331 Date d'inscription Statut Modérateur, Contributeur sécurité Dernière intervention -
lami20j Messages postés 21331 Date d'inscription Statut Modérateur, Contributeur sécurité Dernière intervention -
Bonjour,
je dois afficher un deuxième tableau mais je dois afficher une et une seule fois les nombres même si il s'y trouve plusieurs fois.
peut-on me corriger? ( la partie en commentaire et gras)
merci
#include <stdio.h>
#include<stdlib.h>
#include <time.h>
void main (void)
{
int tab[10][10];
int i,j,nbr,min,max,nbre,nbfois=0;
srand(time(NULL));
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
nbr=rand()%100+1;
tab[i][j]= nbr;
printf( "%d\t", tab[i][j] );
}
printf("\n");
}
min=max=tab[0][0];
/* recherche du minimum et maximum*/
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if( min > tab[i][j] )
{
min= tab[i][j];
}
if( max < tab[i][j] )
{
max=tab[i][j];
}
}
}
printf("le minimum est de : %d\n",min);
printf("le maximum est de: %d\n",max);
printf("\n");
/* demande d'un nombre et affichage des occurrences */
printf("entrez un nombre\n");
scanf("%d",&nbre);
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if ( nbre == tab[i][j])
nbfois = nbfois++;
// if ( nbre == tab[i][j]) nb_fois++;
}
}
printf(" le nombre encoder se trouve %d fois dans le tableau\n ", nbfois);
/*recherche des nombres et affichages une et une seule fois
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
nbr=rand()%100+1;
tab[i][j]= nbr;
printf( "%d\t", tab[i][j] );
if(nbfois >=1)
printf("%d",nbre);
printf("\n"); */
}
printf("\n");
}
}
je dois afficher un deuxième tableau mais je dois afficher une et une seule fois les nombres même si il s'y trouve plusieurs fois.
peut-on me corriger? ( la partie en commentaire et gras)
merci
#include <stdio.h>
#include<stdlib.h>
#include <time.h>
void main (void)
{
int tab[10][10];
int i,j,nbr,min,max,nbre,nbfois=0;
srand(time(NULL));
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
nbr=rand()%100+1;
tab[i][j]= nbr;
printf( "%d\t", tab[i][j] );
}
printf("\n");
}
min=max=tab[0][0];
/* recherche du minimum et maximum*/
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if( min > tab[i][j] )
{
min= tab[i][j];
}
if( max < tab[i][j] )
{
max=tab[i][j];
}
}
}
printf("le minimum est de : %d\n",min);
printf("le maximum est de: %d\n",max);
printf("\n");
/* demande d'un nombre et affichage des occurrences */
printf("entrez un nombre\n");
scanf("%d",&nbre);
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if ( nbre == tab[i][j])
nbfois = nbfois++;
// if ( nbre == tab[i][j]) nb_fois++;
}
}
printf(" le nombre encoder se trouve %d fois dans le tableau\n ", nbfois);
/*recherche des nombres et affichages une et une seule fois
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
nbr=rand()%100+1;
tab[i][j]= nbr;
printf( "%d\t", tab[i][j] );
if(nbfois >=1)
printf("%d",nbre);
printf("\n"); */
}
printf("\n");
}
}
A voir également:
- Langage c: tableau
- Langage ascii - Guide
- Langage binaire - Guide
- Pascal langage - Télécharger - Édition & Programmation
- Langage visual basic - Télécharger - Langages
- Langage basic gratuit - Télécharger - Édition & Programmation