1.å
³äºcè¯è¨ä¸çrand()
å ³äºcè¯è¨ä¸çrand()
å 为éæºæ°ç§åä¸å
ç¨srand设置ä¸ä¸ªä¸åçéæºæ°ç§åå³å¯
ä¾ç¨
/* rand example: guess the number */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
int iSecret,微信二维码导航源码 iGuess;
/* initialize random seed: */
srand ( time(NULL) );
/* generate secret number: */
iSecret = rand() % + 1;
do {
printf ("Guess the number (1 to ): ");
scanf ("%d",&iGuess);
if (iSecret<iGuess) puts ("The secret number is lower");
else if (iSecret>iGuess) puts ("The secret number is higher");
} while (iSecret!=iGuess);
puts ("Congratulations!");
return 0;
}