程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C >> 關於C >> 時間函數舉例4,一個猜數游戲,判斷一個人反應快慢

時間函數舉例4,一個猜數游戲,判斷一個人反應快慢

編輯:關於C
程序源代碼: #include "time.h" #include "stdlib.h" #include "stdio.h" main() {char c; clock_t start,end; time_t a,b; double var; int i,guess; srand(time(NULL)); printf("do you want to play it.('y' or 'n') \n"); loop: while((c=getchar())=='y') { i=rand()%100; printf("\nplease input number you guess:\n"); start=clock(); a=time(NULL); scanf("%d",&guess); while(guess!=i) {if(guess>i) {printf("please input a little smaller.\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 you %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 normal! \1\1\n\n"); else printf("\1\1 you are stupid! \1\1\n\n"); printf("\1\1 Congradulations \1\1\n\n"); printf("The number you guess is %d",i); } printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n"); if((c=getch())=='y') goto loop;

}

*
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved