此代码若在C编译器下运行须将中文翻译为英文。或者使用中文DOS运行也可。 代码如下: /**************************************** 猜数字小游戏 ****************************************/ #include "time.h" #include "stdlib.h" #include "stdio.h" #include "conio.h" main() { char c; clock_t start,end; time_t a,b; double var; int i,guess; srand(time(NULL)); printf("您已准备好进行挑战了吗?('y' or 'n') \n"); loop: while((c=getchar())=='y') { i=rand()%100; printf("\n请输入您要竞猜的数字:\n"); start=clock(); a=time(NULL); scanf("%d",&guess); while(guess!=i) { if(guess>i) { printf("您输入的数字大了...!\n"); scanf("%d",&guess); } else { printf("您输入的数字小了...!\n"); scanf("%d",&guess); } } end=clock(); b=time(NULL); printf("\1: 您挑战的时间为:%6.3f seconds\n",var=(double)(end-start)/18.2); /* printf("\1: 平均挑战时间! %6.3f seconds\n\n",difftime(b,a)); */ if(var<15) printf("\1\1 您真聪明! \1\1\n\n"); else if(var<25) printf("\1\1 一般一般! \1\1\n\n"); else printf("\1\1 继续努力! \1\1\n\n"); printf("\1\1 您猜中的数字是: %d",i); } printf("\n你想再来一局吗?(\"yy\".or.\"n\")\n"); if((c=getch())=='y') { goto loop; } } (责任编辑:admin) |