《2022年经典c程序100例==91--100(1).docx》由会员分享,可在线阅读,更多相关《2022年经典c程序100例==91--100(1).docx(5页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、2022年经典c程序100例=91-100(1)题目:时间函数举例11.程序分析:2.程序源代码:#include stdio.h#include time.hvoid 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(<)
2、; /*tranfer to Greenwich time*/}=题目:时间函数举例21.程序分析:2.程序源代码:/*calculate time*/#include time.h#include stdio.hmain(){ 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);}=题目:
3、时间函数举例31.程序分析:2.程序源代码:/*calculate time*/#include time.h#include stdio.hmain(){ 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);}=题目:时间函数举例4,一个猜数嬉戏,推断一个人反应快慢。(版主初学时编的)
4、1.程序分析:2.程序源代码:#include time.h#include stdlib.h#include stdio.hmain(){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()%100;printf(please input number you guess:);start=clock();a=time(
5、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 clever! 11);else if(var<25)printf(11 you are normal! 11);elseprintf(11 you are stupid! 11);printf(11 Congradulations 11);printf(The number you guess is %d,i);
限制150内