首页 > 其他 > 详细

C 猜数游戏

时间:2016-03-12 13:16:00      阅读:239      评论:0      收藏:0      [点我收藏+]


char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
loop:
printf("DO YOU WANT TO PLAY IT .(‘y‘ or ‘n‘)\n");

while((c=getchar())==‘y‘)
{

 


i=rand()%100;

printf("\n please input number you guess:\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)
{
if(guess!=i)
{
if(guess>i)
{
printf("please input a little smaler.\n");
scanf("%d",&guess);
}
else
{
printf("please input a little bigger\n");
scanf("%d", &guess);
}

}
end=clock();
b=time(NULL);
printf("\1:it took you %6.3f seconds\n",var=(double)(end-start)/18.2);
printf("\1:it took %6.3f seconds\n\n",difftime(b,a));
if(var<15)
printf("\1\1 you are very clever! \1\1\n\n");
else if(var<25)
printf("\1\1 you are norma!\1\1\n\n");
else
printf("\1\1 you are stupid ! \1\1\n\n");
printf("\1\1 congreatulations \1\1\n\n ");
printf("the number you guess is %d",i);


}
printf("\n do you want to try it agin ?(‘y‘ or ‘n‘)\n");
c=getch();

if(c==‘y‘)
printf("\n do you want to try it agin ?(‘y‘ or ‘n‘)\n");

 

//goto loop;


}

//return 0;


/*//你也可以用clock函数来计算你的机器运行一个循环或者处理其它事件到底花了多少时间:

long i = 10000000L;
clock_t start, finish;
double duration;
//测量一个事件持续的时间
printf( "Time to do %ld empty loops is ", i) ;
start = clock();
while( i-- );
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf( "%f seconds\n", duration );
system("pause");

*/

 

 

 

 

 


}

C 猜数游戏

原文:http://www.cnblogs.com/locean/p/5268322.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!