27 lines
522 B
C
27 lines
522 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <time.h>
|
||
|
int main(void){
|
||
|
srand(time(0));
|
||
|
int tab[10];
|
||
|
int i;
|
||
|
for(i=0;i<10;i++){
|
||
|
tab[i]=(rand()%(50+1-(-50)))-50;
|
||
|
}
|
||
|
for(i=0;i<10;i++){
|
||
|
printf("%d, ",tab[i]);
|
||
|
}
|
||
|
|
||
|
int look;
|
||
|
printf("\n Rentrez un nombre,\n si le nombre se trouve dans le tableau son indice sera affiché \n (le cas écheant -1 sera affiché):");
|
||
|
scanf("%d",&look);
|
||
|
int indice;
|
||
|
for(i=0;i<10;i++){
|
||
|
if(tab[i]==look){
|
||
|
indice=i;
|
||
|
}
|
||
|
}
|
||
|
printf("indice : %d \n", indice);
|
||
|
|
||
|
return EXIT_SUCCESS;
|
||
|
}
|