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')
");
while((c=getchar())=='y')
{
i=rand()%100;
printf("
please input number you guess:
");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)
{
if(guess!=i)
{
if(guess>i)
{
printf("please input a little smaler.
");
scanf("%d",&guess);
}
else
{
printf("please input a little bigger
");
scanf("%d", &guess);
}
}
end=clock();
b=time(NULL);
printf("1:it took you %6.3f seconds
",var=(double)(end-start)/18.2);
printf("1:it took %6.3f seconds
",difftime(b,a));
if(var<15)
printf("11 you are very clever! 11
");
else if(var<25)
printf("11 you are norma!11
");
else
printf("11 you are stupid ! 11
");
printf("11 congreatulations 11
");
printf("the number you guess is %d",i);
}
printf("
do you want to try it agin ?('y' or 'n')
");
c=getch();
if(c=='y')
printf("
do you want to try it agin ?('y' or '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
", duration );
system("pause");
*/
}