欢迎来到天天文库
浏览记录
ID:32391771
大小:34.50 KB
页数:10页
时间:2019-02-04
《经典c程序阅读》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、经典c程序100例==91--100【程序91】题目:时间函数举例11.程序分析:2.程序源代码:#include"stdio.h"#include"time.h"voidmain(){time_tlt;/*definealonginttimevarible*/lt=time(NULL);/*systemtimeanddate*/printf(ctime(<));/*englishformatoutput*/printf(asctime(localtime(<)));/*tranfertotm*/printf(asctime(gmtime(<)));/*tranfert
2、oGreenwichtime*/}==============================================================【程序92】题目:时间函数举例21.程序分析: 2.程序源代码:/*calculatetime*/#include"time.h"#include"stdio.h"main(){time_tstart,end;inti;start=time(NULL);for(i=0;i<3000;i++){printf("1111111111");}end=time(NULL);pri
3、ntf("1:Thedifferentis%6.3f",difftime(end,start));}==============================================================【程序93】题目:时间函数举例31.程序分析:2.程序源代码:/*calculatetime*/#include"time.h"#include"stdio.h"main(){clock_tstart,end;inti;doublevar;start=clock();for(i=0;i<10000;i++){printf("11111
4、11111");}end=clock();printf("1:Thedifferentis%6.3f",(double)(end-start));}==============================================================【程序94】题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。(版主初学时编的)1.程序分析:2.程序源代码:#include"time.h"#include"stdlib.h"#include"stdio.h"main(){charc;clock_tstart,end;tim
5、e_ta,b;doublevar;inti,guess;srand(time(NULL));printf("doyouwanttoplayit.('y'or'n')");loop:while((c=getchar())=='y'){i=rand()%100;printf("pleaseinputnumberyouguess:");start=clock();a=time(NULL);scanf("%d",&guess);while(guess!=i){if(guess>i){printf("pleaseinputalittlesmaller.");sca
6、nf("%d",&guess);}else{printf("pleaseinputalittlebigger.");scanf("%d",&guess);}}end=clock();b=time(NULL);printf("1:Ittookyou%6.3fseconds",var=(double)(end-start)/18.2);printf("1:ittookyou%6.3fseconds",difftime(b,a));if(var<15)printf("11Youareveryclever!11");elseif(var<25
7、)printf("11youarenormal!11");elseprintf("11youarestupid!11");printf("11Congradulations11");printf("Thenumberyouguessis%d",i);}printf("doyouwanttotryitagain?("yy".or."n")");if((c=getch())=='y')gotoloop;}======================================
此文档下载收益归作者所有