I'm developing a program in C that randomly generates a thousand numbers and that in the end appears the largest and smallest of them. For this, I'm using rand()
.
But I have a problem. When I run only less than 300 numbers are generated and not from 0 to 1000. But from 707 to 1000.
Look below what I did:
include stdio.h
include stdlib.h
include windows.h
main(){
int numero,numero2;
int total1 = 0;
int total2 = 1001;
for (numero = 1; numero != 1001; numero++){
numero2 = rand () % 1000;
printf("Numero %d: %d \n ",numero,numero2);
if (numero2 > total1){
total1 = numero2;
}
if (numero2 < total2){
total2 = numero2;
}
}
printf("\n");
printf("O maior numero e: %d \n\n",total1);
printf("O menor numero e: %d \n\n",total2);
system("pause");
return 0;
}
Where am I going wrong?