很很简单的一个程序,练习随机数: #include <stdio.h> #include <time.h> #include <stdlib.h> void main(){ int chosen; int guess; int count=3; int limits=20; srand(time(NULL)); chosen=1+rand()%limits; //一个从1..20的随机数 puts("you have 3 times to guess a number between 1~20"); puts("first:"); while(count--){ scanf("%d",&guess); if(chosen==guess) { puts("Ok,you guess it!"); break; } else if(count) printf("Sorry,it isn't!you have only %d %s to try.../n",count,(count==1?"time":"times")); }//while if(count<0) puts("You failed...I'am sorry to tell you :your IQ is so low that I can say nothing more"); }//main