<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0046)http://www.ccshu.org/teachers/kim/REF/cj10.htm -->
<HTML><HEAD><TITLE>C语言经典例题100例-10</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.2873" name=GENERATOR></HEAD>
<BODY>【程序91】 <BR>题目:时间函数举例1 <BR>1.程序分析: <BR>2.程序源代码: <BR>#include "stdio.h"
<BR>#include "time.h" <BR>void main() <BR>{ time_t lt; /*define a longint time
varible*/ <BR>lt=time(NULL);/*system time and date*/ <BR>printf(ctime(<));
/*english format output*/ <BR>printf(asctime(localtime(<)));/*tranfer to tm*/
<BR>printf(asctime(gmtime(<))); /*tranfer to Greenwich time*/ <BR>}
<BR>【程序92】 <BR>题目:时间函数举例2 <BR>1.程序分析: <BR>2.程序源代码: <BR>/*calculate
time*/ <BR>#include "time.h" <BR>#include "stdio.h" <BR>main() <BR>{ time_t
start,end; <BR>int i; <BR>start=time(NULL); <BR>for(i=0;i<3000;i++) <BR>{
printf("\1\1\1\1\1\1\1\1\1\1\n");} <BR>end=time(NULL); <BR>printf("\1: The
different is %6.3f\n",difftime(end,start)); <BR>} <BR>【程序93】 <BR>题目:时间函数举例3
<BR>1.程序分析: <BR>2.程序源代码: <BR>/*calculate time*/ <BR>#include "time.h"
<BR>#include "stdio.h" <BR>main() <BR>{ clock_t start,end; <BR>int i; <BR>double
var; <BR>start=clock(); <BR>for(i=0;i<10000;i++) <BR>{
printf("\1\1\1\1\1\1\1\1\1\1\n");} <BR>end=clock(); <BR>printf("\1: The
different is %6.3f\n",(double)(end-start)); <BR>} <BR>【程序94】
<BR>题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。(版主初学时编的) <BR>1.程序分析: <BR>2.程序源代码: <BR>#include
"time.h" <BR>#include "stdlib.h" <BR>#include "stdio.h" <BR>main() <BR>{char c;
<BR>clock_t start,end; <BR>time_t a,b; <BR>double var; <BR>int i,guess;
<BR>srand(time(NULL)); <BR>printf("do you want to play it.('y' or 'n') \n");
<BR>loop: <BR>while((c=getchar())=='y') <BR>{ <BR>i=rand()%100;
<BR>printf("\nplease input number you guess:\n"); <BR>start=clock();
<BR>a=time(NULL); <BR>scanf("%d",&guess); <BR>while(guess!=i)
<BR>{if(guess>i) <BR>{printf("please input a little smaller.\n");
<BR>scanf("%d",&guess);} <BR>else <BR>{printf("please input a little
bigger.\n"); <BR>scanf("%d",&guess);} <BR>} <BR>end=clock();
<BR>b=time(NULL); <BR>printf("\1: It took you %6.3f
seconds\n",var=(double)(end-start)/18.2); <BR>printf("\1: it took you %6.3f
seconds\n\n",difftime(b,a)); <BR>if(var<15) <BR>printf("\1\1 You are very
clever! \1\1\n\n"); <BR>else if(var<25) <BR>printf("\1\1 you are normal!
\1\1\n\n"); <BR>else <BR>printf("\1\1 you are stupid! \1\1\n\n");
<BR>printf("\1\1 Congradulations \1\1\n\n"); <BR>printf("The number you guess is
%d",i); <BR>} <BR>printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");
<BR>if((c=getch())=='y') <BR>goto loop; <BR>} <BR>【程序95】 <BR>题目:家庭财务管理小程序
<BR>1.程序分析: <BR>2.程序源代码: <BR>/*money management system*/ <BR>#include "stdio.h"
<BR>#include "dos.h" <BR>main() <BR>{ <BR>FILE *fp; <BR>struct date d; <BR>float
sum,chm=0.0; <BR>int len,i,j=0; <BR>int c; <BR>char
ch[4]="",ch1[16]="",chtime[12]="",chshop[16],chmoney[8]; <BR>pp: clrscr();
<BR>sum=0.0;
<BR>gotoxy(1,1);printf("|---------------------------------------------------------------------------|");
<BR>gotoxy(1,2);printf("| money management system(C1.0) 2000.03 |");
<BR>gotoxy(1,3);printf("|---------------------------------------------------------------------------|");
<BR>gotoxy(1,4);printf("| -- money records -- | -- today cost list -- |");
<BR>gotoxy(1,5);printf("| ------------------------
|-------------------------------------|"); <BR>gotoxy(1,6);printf("| date:
-------------- | |"); <BR>gotoxy(1,7);printf("| | | | |");
<BR>gotoxy(1,8);printf("| -------------- | |"); <BR>gotoxy(1,9);printf("| thgs:
------------------ | |"); <BR>gotoxy(1,10);printf("| | | | |");
<BR>gotoxy(1,11);printf("| ------------------ | |"); <BR>gotoxy(1,12);printf("|
cost: ---------- | |"); <BR>gotoxy(1,13);printf("| | | | |");
<BR>gotoxy(1,14);printf("| ---------- | |"); <BR>gotoxy(1,15);printf("| | |");
<BR>gotoxy(1,16);printf("| | |"); <BR>gotoxy(1,17);printf("| | |");
<BR>gotoxy(1,18);printf("| | |"); <BR>gotoxy(1,19);printf("| | |");
<BR>gotoxy(1,20);printf("| | |"); <BR>gotoxy(1,21);printf("| | |");
<BR>gotoxy(1,22);printf("| | |");
<BR>gotoxy(1,23);printf("|---------------------------------------------------------------------------|");
<BR>i=0; <BR>getdate(&d);
<BR>sprintf(chtime,"%4d.%02d.%02d",d.da_year,d.da_mon,d.da_day); <BR>for(;;)
<BR>{ <BR>gotoxy(3,24);printf(" Tab __browse cost list Esc __quit");
<BR>gotoxy(13,10);printf(" "); <BR>gotoxy(13,13);printf(" ");
<BR>gotoxy(13,7);printf("%s",chtime); <BR>j=18; <BR>ch[0]=getch();
<BR>if(ch[0]==27) <BR>break; <BR>strcpy(chshop,""); <BR>strcpy(chmoney,"");
<BR>if(ch[0]==9) <BR>{ <BR>mm:i=0; <BR>fp=fopen("home.dat","r+");
<BR>gotoxy(3,24);printf(" "); <BR>gotoxy(6,4);printf(" list records ");
<BR>gotoxy(1,5);printf("|-------------------------------------|");
<BR>gotoxy(41,4);printf(" "); <BR>gotoxy(41,5);printf(" |");
<BR>while(fscanf(fp,"%10s%14s%f\n",chtime,chshop,&chm)!=EOF) <BR>{ if(i==36)
<BR>{ getch(); <BR>i=0;} <BR>if ((i%36)<17) <BR>{ gotoxy(4,6+i); <BR>printf("
"); <BR>gotoxy(4,6+i);} <BR>else <BR>if((i%36)>16) <BR>{ gotoxy(41,4+i-17);
<BR>printf(" "); <BR>gotoxy(42,4+i-17);} <BR>i++; <BR>sum=sum+chm;
<BR>printf("%10s %-14s %6.1f\n",chtime,chshop,chm);}
<BR>gotoxy(1,23);printf("|---------------------------------------------------------------------------|");
<BR>gotoxy(1,24);printf("| |");
<BR>gotoxy(1,25);printf("|---------------------------------------------------------------------------|");
<BR>gotoxy(10,24);printf("total is %8.1f$",sum); <BR>fclose(fp);
<BR>gotoxy(49,24);printf("press any key to.....");getch();goto pp; <BR>}
<BR>else <BR>{ <BR>while(ch[0]!='\r') <BR>{ if(j<10) <BR>{
strncat(chtime,ch,1); <BR>j++;} <BR>if(ch[0]==8) <BR>{ <BR>len=strlen(chtime)-1;
<BR>if(j>15) <BR>{ len=len+1; j=11;} <BR>strcpy(ch1,""); <BR>j=j-2;
<BR>strncat(ch1,chtime,len); <BR>strcpy(chtime,"");
<BR>strncat(chtime,ch1,len-1); <BR>gotoxy(13,7);printf(" ");}
<BR>gotoxy(13,7);printf("%s",chtime);ch[0]=getch(); <BR>if(ch[0]==9) <BR>goto
mm; <BR>if(ch[0]==27) <BR>exit(1); <BR>} <BR>gotoxy(3,24);printf(" ");
<BR>gotoxy(13,10); <BR>j=0; <BR>ch[0]=getch(); <BR>while(ch[0]!='\r') <BR>{ if
(j<14) <BR>{ strncat(chshop,ch,1); <BR>j++;} <BR>if(ch[0]==8) <BR>{
len=strlen(chshop)-1; <BR>strcpy(ch1,""); <BR>j=j-2;
<BR>strncat(ch1,chshop,len); <BR>strcpy(chshop,"");
<BR>strncat(chshop,ch1,len-1); <BR>gotoxy(13,10);printf(" ");}
<BR>gotoxy(13,10);printf("%s",chshop);ch[0]=getch();} <BR>gotoxy(13,13);
<BR>j=0; <BR>ch[0]=getch(); <BR>while(ch[0]!='\r') <BR>{ if (j<6) <BR>{
strncat(chmoney,ch,1); <BR>j++;} <BR>if(ch[0]==8) <BR>{ len=strlen(chmoney)-1;
<BR>strcpy(ch1,""); <BR>j=j-2; <BR>strncat(ch1,chmoney,len);
<BR>strcpy(chmoney,""); <BR>strncat(chmoney,ch1,len-1);
<BR>gotoxy(13,13);printf(" ");}
<BR>gotoxy(13,13);printf("%s",chmoney);ch[0]=getch();}
<BR>if((strlen(chshop)==0)||(strlen(chmoney)==0)) <BR>continue;
<BR>if((fp=fopen("home.dat","a+"))!=NULL);
<BR>fprintf(fp,"%10s%14s%6s",chtime,chshop,chmoney); <BR>fputc('\n',fp);
<BR>fclose(fp); <BR>i++; <BR>gotoxy(41,5+i); <BR>printf("%10s %-14s
%-6s",chtime,chshop,chmoney); <BR>}}} <BR>【程序96】 <BR>题目:计算字符串中子串出现的次数
<BR>1.程序分析: <BR>2.程序源代码: <BR>#include "string.h" <BR>#include "stdio.h"
<BR>main() <BR>{ char str1[20],str2[20],*p1,*p2; <BR>int sum=0;
<BR>printf("please input two strings\n"); <BR>scanf("%s%s",str1,str2);
<BR>p1=str1;p2=str2; <BR>while(*p1!='\0') <BR>{ <BR>if(*p1==*p2)
<BR>{while(*p1==*p2&&*p2!='\0') <BR>{p1++; <BR>p2++;}
liuquanle
- 粉丝: 5
- 资源: 23
最新资源
- 基于Kotlin语言的Android开发工具类集合源码
- 零延迟 DirectX 11 扩展实用程序.zip
- 基于Java的语音识别系统设计源码
- 基于Java和HTML的yang_home766个人主页设计源码
- 基于Java与前端技术的全国实时疫情信息网站设计源码
- 基于鸿蒙系统的HarmonyHttpClient设计源码,纯Java实现类似OkHttp的HttpNet框架与优雅的Retrofit注解解析
- 基于HTML和JavaScript的廖振宇图书馆前端设计源码
- 基于Java的Android开发工具集合源码
- 通过 DirectX 12 Hook (kiero) 实现通用 ImGui.zip
- 基于Java开发的YY网盘个人网盘设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈