爪哇社区
  • 首页
  • 文章
  • 问答
  • 导航



  1. 首页
  2. 文章列表
  3. 经典C语言编程100例——题目+答案代码(完结)

经典C语言编程100例——题目+答案代码(完结)

发布:HelloJq 时间:2025-05-15

【程序 91】

题目:时间函数举例 1
1.程序分析:
2.程序源代码:

#include "" #include "" void main() { time_t lt; /*define a longint time varible*/ lt=time(NULL);/*system time and date*/ printf(ctime(<)); /*english format output*/ printf(asctime(localtime(<)));/*tranfer to tm*/ printf(asctime(gmtime(<))); /*tranfer to Greenwich time*/ } 

【程序 92】

题目:时间函数举例 2
1.程序分析:
2.程序源代码:

/*calculate time*/ #include "" #include "" main() { time_t start,end; int i; start=time(NULL); for(i=0;i<3000;i++) { printf("1111111111
");} end=time(NULL); printf("1: The different is %6.3f
",difftime(end,start)); } 

【程序 93】

题目:时间函数举例 3
1.程序分析:
2.程序源代码:

/*calculate time*/ #include "" #include "" main() { clock_t start,end; int i; double var; start=clock(); for(i=0;i<10000;i++) { printf("1111111111
");} end=clock(); printf("1: The different is %6.3f
",(double)(end-start)); } 

【程序 94】

题目:时间函数举例 4,一个猜数游戏,判断一个人反应快慢。
1.程序分析:
2.程序源代码:

#include "" #include "" #include "" 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') 
"); loop: while((c=getchar())=='y') { i=rand() 0; printf("
please input number you guess:
"); start=clock(); a=time(NULL); scanf("%d",&guess); while(guess!=i) {if(guess>i) {printf("please input a little smaller.
"); 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 you %6.3f seconds

",difftime(b,a)); if(var<15) printf("11 You are very smart! 11

"); else if(var<25) printf("11 you are ordinary! 11

"); else printf("11 you are stupid! 11

"); printf("11 Congradulations 11

"); printf("The number you guess is %d",i); } printf("
do you want to try it again?("yy".or."n")
"); if((c=getch())=='y') goto loop; }


爪哇社区 © 2024