时间函数举例.docx
- 文档编号:2448391
- 上传时间:2022-10-29
- 格式:DOCX
- 页数:4
- 大小:14.64KB
时间函数举例.docx
《时间函数举例.docx》由会员分享,可在线阅读,更多相关《时间函数举例.docx(4页珍藏版)》请在冰豆网上搜索。
时间函数举例
题目:
时间函数举例
1.程序分析:
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(<)));/*tranfertoGreenwichtime*/
}
【程序92】
题目:
时间函数举例2
1.程序分析:
2.程序源代码:
/*calculatetime*/
#include"time.h"
#include"stdio.h"
main()
{
time_tstart,end;
inti;
start=time(NULL);
for(i=0;i<3000;i++)
{
printf("\1\1\1\1\1\1\1\1\1\1\n");
}
end=time(NULL);
printf("\1:
Thedifferentis%6.3f\n",difftime(end,start));
}
【程序93】
题目:
时间函数举例3
1.程序分析:
2.程序源代码:
/*calculatetime*/
#include"time.h"
#include"stdio.h"
main()
{
clock_tstart,end;
inti;
doublevar;
start=clock();
for(i=0;i<10000;i++)
{
printf("\1\1\1\1\1\1\1\1\1\1\n");
}
end=clock();
printf("\1:
Thedifferentis%6.3f\n",(double)(end-start));
}
【程序94】
题目:
时间函数举例4,一个猜数游戏,判断一个人反应快慢。
(版主初学时编的)
1.程序分析:
2.程序源代码:
#include"time.h"
#include"stdlib.h"
#include"stdio.h"
main()
{
charc;
clock_tstart,end;
time_ta,b;
doublevar;
inti,guess;
srand(time(NULL));
printf("doyouwanttoplayit.('y'or'n')\n");
loop:
while((c=getchar())=='y')
{
i=rand()%100;
printf("\npleaseinputnumberyouguess:
\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!
=i)
{
if(guess>i)
{
printf("pleaseinputalittlesmaller.\n");
scanf("%d",&guess);
}
else
{
printf("pleaseinputalittlebigger.\n");
scanf("%d",&guess);
}
}
end=clock();
b=time(NULL);
printf("\1:
Ittookyou%6.3fseconds\n",var=(double)(end-start)/18.2);
printf("\1:
ittookyou%6.3fseconds\n\n",difftime(b,a));
if(var<15)
printf("\1\1Youareveryclever!
\1\1\n\n");
elseif(var<25)
printf("\1\1youarenormal!
\1\1\n\n");
else
printf("\1\1youarestupid!
\1\1\n\n");
printf("\1\1Congradulations\1\1\n\n");
printf("Thenumberyouguessis%d",i);
}
printf("\ndoyouwanttotryitagain?
(\"yy\".or.\"n\")\n");
if((c=getch())=='y')
gotoloop;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 时间 函数 举例
![提示](https://static.bdocx.com/images/bang_tan.gif)