时间函数举例.docx

上传人:b****3 文档编号:2448391 上传时间:2022-10-29 格式:DOCX 页数:4 大小:14.64KB
下载 相关 举报
时间函数举例.docx_第1页
第1页 / 共4页
时间函数举例.docx_第2页
第2页 / 共4页
时间函数举例.docx_第3页
第3页 / 共4页
时间函数举例.docx_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

时间函数举例.docx

《时间函数举例.docx》由会员分享,可在线阅读,更多相关《时间函数举例.docx(4页珍藏版)》请在冰豆网上搜索。

时间函数举例.docx

时间函数举例

题目:

时间函数举例

  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;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1