#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main (int argc, const char * argv[]) {
Insert code here ...
printf ("Hello, world!\n");
int a,b,i;
{
Srand ((unsigned int) time (0));
b = rand ()%100 + 1;
printf ("%d\n", b);//hides randomly generated numbers.
}
Generate a random number
while (1) {
printf ("Insert the number you thinking, please\n");
scanf ("%d", &a);//scanf There is no impurity inside, if there is a space or something will cause the input of the first data can not run, starting from the second data to run.
i=i+1;
if (a>b)
{
printf ("Too big, smaller would be better.") \ n ");
}
else if (a<b) {
printf ("Too small, you should think of a bit more \ n");
}
else{
printf ("Congratulations. Correct!!! You guessed it for%d times.!!! You're so smart, "I";
break;//no break will keep running
}
}
int a,b,i;
//
Srand ((unsigned int) time (0));
Srand ((unsigned int) time (0));
//
b = rand ()%100 + 1;
printf ("%d\n", b);
for (i=0; i<100; i++) {
printf ("Please enter a number \ n");
scanf ("%d", &a);
if (a>b) {
printf ("??, the number you entered is big");
// }
else if (a<b)
printf ("??, the number you entered is small");
Else
{printf ("Congratulations, correct");
Break
// }
// }
return 0;
}
/* Generates a random number complete code
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main ()
{
Srand ((unsigned int) time (0));
int a[20];
for (int i = 0; i <; i++)
{
A[i] = rand ()%100 + 1;
printf ("%d\n", A[i]);
}
return 0;
} */
C-language guessing game-generating a random number