⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list10.htm

📁 经典一百例(c语言版)
💻 HTM
📖 第 1 页 / 共 3 页
字号:
              value=#CCFFCC>绿色</OPTION>
              <OPTION value=#99CCFF>蓝色</OPTION>
              <OPTION value=#CCFFFF>青色</OPTION>
              <OPTION 
            value=#FFCCCC>综色</OPTION>
            </SELECT>
            字号     
            <SELECT 
            style="WIDTH: 60px; HEIGHT: 20px; fontsize: 9pt" 
            onchange=setFontSize(this.value); name=selfontsize>
              <OPTION 
              value=9pt selected>9 pt</OPTION>
              <OPTION value=10pt>10 pt</OPTION>
              <OPTION value=12pt>12 pt</OPTION>
              <OPTION value=14pt>14 pt</OPTION>
              <OPTION value=16pt>16 pt</OPTION>
              <OPTION 
              value=19pt>19 pt</OPTION>
            </SELECT>
            </font></TD>
          <TD class=zi width=85><font size="2"><a href="javascript:saveit();" onMouseOver="MM_showHideLayers('Layer1','','show')" onMouseOut="MM_showHideLayers('Layer1','','hide')"><img src="images/save.png" width="23" height="22" name="s" onMouseOver="MM_swapImage('s','','images/save2.png',1)" border="0" align="absbottom"></a>保存设置</font></TD>
          <TD class=zi width=2 ><font size="2">&nbsp;</font></TD>
                      <TD class=zi width=164><font size="2"> &nbsp;&nbsp;人气指数:<font color="#FF0000">162368</font>&nbsp; 
                        &nbsp;</font></TD>    
        </TR>
        </TBODY> 
      </TABLE>
    </TD>
  </TR>
  <TR vAlign=center align=left>
    <TD bgColor=#BDCFF7 colSpan=2 height=370>
      <TABLE height=360 cellSpacing=0 borderColorDark=#4275D6 cellPadding=5 
      width=640 align=center bgColor=#ffffff borderColorLight=#ffffff 
        border=1>
        <TBODY> 
        <TR vAlign=top align=left>
          <TD id=thetd style="FONT-SIZE: 10pt">
                        <div align="left" style="width: 626; height: 132"> 
                          <p align="left"> 
                            <html>
<head>
<style type="text/css">
td { font-size: 9pt }
body { color: #000000; font-size: 9pt; line-height: 150% }
a:link { color: #000000; text-decoration: none }
a:visited { color: #000000; text-decoration: none }
a:active { color: #000000; text-decoration: none }
a:hover { color: #ff0000; text-decoration: underline }
</style>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<p align="left"><font color="#FF9933"><b><font size="5">    <font color="#3300CC">经典c程序100例==91--100</font></font></b></font></p>
<p><font color="#990000">【程序91】</font><br>
  题目:时间函数举例1<br>
  1.程序分析:<br>
  2.程序源代码:<br>
  #include &quot;stdio.h&quot;<br>
  #include &quot;time.h&quot;<br>
  void main()<br>
  { time_t lt; /*define a longint time varible*/<br>
  lt=time(NULL);/*system time and date*/<br>
  printf(ctime(&lt;)); /*english format output*/<br>
  printf(asctime(localtime(&lt;)));/*tranfer to tm*/<br>
  printf(asctime(gmtime(&lt;))); /*tranfer to Greenwich time*/<br>
  }<br>
  ==============================================================<br>
  <font color="#990000">【程序92】</font><br>
  题目:时间函数举例2<br>
  1.程序分析:           <br>
  2.程序源代码:<br>
  /*calculate time*/<br>
  #include &quot;time.h&quot;<br>
  #include &quot;stdio.h&quot;<br>
  main()<br>
  { time_t start,end;<br>
  int i;<br>
  start=time(NULL);<br>
  for(i=0;i&lt;3000;i++)<br>
  { printf(&quot;\1\1\1\1\1\1\1\1\1\1\n&quot;);}<br>
  end=time(NULL);<br>
  printf(&quot;\1: The different is %6.3f\n&quot;,difftime(end,start));<br>
  }<br>
  ==============================================================<br>
  <font color="#990000">【程序93】</font><br>
  题目:时间函数举例3<br>
  1.程序分析:<br>
  2.程序源代码:<br>
  /*calculate time*/<br>
  #include &quot;time.h&quot;<br>
  #include &quot;stdio.h&quot;<br>
  main()<br>
  { clock_t start,end;<br>
  int i;<br>
  double var;<br>
  start=clock();<br>
  for(i=0;i&lt;10000;i++)<br>
  { printf(&quot;\1\1\1\1\1\1\1\1\1\1\n&quot;);}<br>
  end=clock();<br>
  printf(&quot;\1: The different is %6.3f\n&quot;,(double)(end-start));<br>
  }<br>
  ==============================================================<br>
  <font color="#990000">【程序94】</font><br>
  题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。(版主初学时编的)<br>
  1.程序分析:<br>
  2.程序源代码:<br>
  #include &quot;time.h&quot;<br>
  #include &quot;stdlib.h&quot;<br>
  #include &quot;stdio.h&quot;<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(&quot;do you want to play it.('y' or 'n') \n&quot;);<br>
  loop:<br>
  while((c=getchar())=='y')<br>
  {<br>
  i=rand()%100;<br>
  printf(&quot;\nplease input number you guess:\n&quot;);<br>
  start=clock();<br>
  a=time(NULL);<br>
  scanf(&quot;%d&quot;,&amp;guess);<br>
  while(guess!=i)<br>
  {if(guess&gt;i)<br>
  {printf(&quot;please input a little smaller.\n&quot;);<br>
  scanf(&quot;%d&quot;,&amp;guess);}<br>
  else<br>
  {printf(&quot;please input a little bigger.\n&quot;);<br>
  scanf(&quot;%d&quot;,&amp;guess);}<br>
  }<br>
  end=clock();<br>
  b=time(NULL);<br>
  printf(&quot;\1: It took you %6.3f seconds\n&quot;,var=(double)(end-start)/18.2);<br>
  printf(&quot;\1: it took you %6.3f seconds\n\n&quot;,difftime(b,a));<br>
  if(var&lt;15)<br>
  printf(&quot;\1\1 You are very clever! \1\1\n\n&quot;);<br>
  else if(var&lt;25)<br>
  printf(&quot;\1\1 you are normal! \1\1\n\n&quot;);<br>
  else<br>
  printf(&quot;\1\1 you are stupid! \1\1\n\n&quot;);<br>
  printf(&quot;\1\1 Congradulations \1\1\n\n&quot;);<br>
  printf(&quot;The number you guess is %d&quot;,i);<br>
  }<br>
  printf(&quot;\ndo you want to try it again?(\&quot;yy\&quot;.or.\&quot;n\&quot;)\n&quot;);<br>
  if((c=getch())=='y')<br>
  goto loop;<br>
  }<br>
  ==============================================================<br>
  <font color="#990000">【程序95】</font><br>
  题目:家庭财务管理小程序<br>
  1.程序分析:<br>
  2.程序源代码:<br>
  /*money management system*/<br>
  #include &quot;stdio.h&quot;<br>
  #include &quot;dos.h&quot;<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]=&quot;&quot;,ch1[16]=&quot;&quot;,chtime[12]=&quot;&quot;,chshop[16],chmoney[8];<br>
  pp: clrscr();<br>
  sum=0.0;<br>
  gotoxy(1,1);printf(&quot;|---------------------------------------------------------------------------|&quot;);<br>
  gotoxy(1,2);printf(&quot;| money management system(C1.0) 2000.03 |&quot;);<br>
  gotoxy(1,3);printf(&quot;|---------------------------------------------------------------------------|&quot;);<br>
  gotoxy(1,4);printf(&quot;| -- money records -- | -- today cost list -- |&quot;);<br>
  gotoxy(1,5);printf(&quot;| ------------------------ |-------------------------------------|&quot;);<br>
  gotoxy(1,6);printf(&quot;| date: -------------- | |&quot;);<br>
  gotoxy(1,7);printf(&quot;| | | | |&quot;);<br>
  gotoxy(1,8);printf(&quot;| -------------- | |&quot;);<br>
  gotoxy(1,9);printf(&quot;| thgs: ------------------ | |&quot;);<br>
  gotoxy(1,10);printf(&quot;| | | | |&quot;);<br>
  gotoxy(1,11);printf(&quot;| ------------------ | |&quot;);<br>
  gotoxy(1,12);printf(&quot;| cost: ---------- | |&quot;);<br>
  gotoxy(1,13);printf(&quot;| | | | |&quot;);<br>
  gotoxy(1,14);printf(&quot;| ---------- | |&quot;);<br>
  gotoxy(1,15);printf(&quot;| | |&quot;);<br>
  gotoxy(1,16);printf(&quot;| | |&quot;);<br>
  gotoxy(1,17);printf(&quot;| | |&quot;);<br>
  gotoxy(1,18);printf(&quot;| | |&quot;);<br>
  gotoxy(1,19);printf(&quot;| | |&quot;);<br>
  gotoxy(1,20);printf(&quot;| | |&quot;);<br>
  gotoxy(1,21);printf(&quot;| | |&quot;);<br>
  gotoxy(1,22);printf(&quot;| | |&quot;);<br>
  gotoxy(1,23);printf(&quot;|---------------------------------------------------------------------------|&quot;);<br>
  i=0;<br>
  getdate(&amp;d);<br>
  sprintf(chtime,&quot;%4d.%02d.%02d&quot;,d.da_year,d.da_mon,d.da_day);<br>
  for(;;)<br>
  {<br>
  gotoxy(3,24);printf(&quot; Tab __browse cost list Esc __quit&quot;);<br>
  gotoxy(13,10);printf(&quot; &quot;);<br>
  gotoxy(13,13);printf(&quot; &quot;);<br>
  gotoxy(13,7);printf(&quot;%s&quot;,chtime);<br>
  j=18;<br>
  ch[0]=getch();<br>
  if(ch[0]==27)<br>
  break;<br>
  strcpy(chshop,&quot;&quot;);<br>
  strcpy(chmoney,&quot;&quot;);<br>
  if(ch[0]==9)<br>
  {<br>
  mm:i=0;<br>
  fp=fopen(&quot;home.dat&quot;,&quot;r+&quot;);<br>
  gotoxy(3,24);printf(&quot; &quot;);<br>
  gotoxy(6,4);printf(&quot; list records &quot;);<br>
  gotoxy(1,5);printf(&quot;|-------------------------------------|&quot;);<br>
  gotoxy(41,4);printf(&quot; &quot;);<br>
  gotoxy(41,5);printf(&quot; |&quot;);<br>
  while(fscanf(fp,&quot;%10s%14s%f\n&quot;,chtime,chshop,&amp;chm)!=EOF)<br>
  { if(i==36)<br>
  { getch();<br>
  i=0;}<br>
  if ((i%36)&lt;17)<br>
  { gotoxy(4,6+i);<br>
  printf(&quot; &quot;);<br>
  gotoxy(4,6+i);}<br>
  else<br>
  if((i%36)&gt;16)<br>
  { gotoxy(41,4+i-17);<br>
  printf(&quot; &quot;);<br>
  gotoxy(42,4+i-17);}<br>
  i++;<br>
  sum=sum+chm;<br>
  printf(&quot;%10s %-14s %6.1f\n&quot;,chtime,chshop,chm);}<br>
  gotoxy(1,23);printf(&quot;|---------------------------------------------------------------------------|&quot;);<br>
  gotoxy(1,24);printf(&quot;| |&quot;);<br>
  gotoxy(1,25);printf(&quot;|---------------------------------------------------------------------------|&quot;);<br>
  gotoxy(10,24);printf(&quot;total is %8.1f$&quot;,sum);<br>
  fclose(fp);<br>
  gotoxy(49,24);printf(&quot;press any key to.....&quot;);getch();goto pp;<br>
  }<br>
  else<br>
  {<br>
  while(ch[0]!='\r')<br>
  { if(j&lt;10)<br>
  { strncat(chtime,ch,1);<br>
  j++;}<br>
  if(ch[0]==8)<br>
  {<br>
  len=strlen(chtime)-1;<br>
  if(j&gt;15)<br>
  { len=len+1; j=11;}<br>
  strcpy(ch1,&quot;&quot;);<br>
  j=j-2;<br>
  strncat(ch1,chtime,len);<br>
  strcpy(chtime,&quot;&quot;);<br>
  strncat(chtime,ch1,len-1);<br>
  gotoxy(13,7);printf(&quot; &quot;);}<br>
  gotoxy(13,7);printf(&quot;%s&quot;,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(&quot; &quot;);<br>
  gotoxy(13,10);<br>
  j=0;<br>
  ch[0]=getch();<br>
  while(ch[0]!='\r')<br>
  { if (j&lt;14)<br>
  { strncat(chshop,ch,1);<br>
  j++;}<br>
  if(ch[0]==8)<br>
  { len=strlen(chshop)-1;<br>
  strcpy(ch1,&quot;&quot;);<br>
  j=j-2;<br>
  strncat(ch1,chshop,len);<br>
  strcpy(chshop,&quot;&quot;);<br>
  strncat(chshop,ch1,len-1);<br>
  gotoxy(13,10);printf(&quot; &quot;);}<br>
  gotoxy(13,10);printf(&quot;%s&quot;,chshop);ch[0]=getch();}<br>
  gotoxy(13,13);<br>
  j=0;<br>
  ch[0]=getch();<br>
  while(ch[0]!='\r')<br>
  { if (j&lt;6)<br>
  { strncat(chmoney,ch,1);<br>
  j++;}<br>
  if(ch[0]==8)<br>
  { len=strlen(chmoney)-1;<br>
  strcpy(ch1,&quot;&quot;);<br>
  j=j-2;<br>
  strncat(ch1,chmoney,len);<br>
  strcpy(chmoney,&quot;&quot;);<br>
  strncat(chmoney,ch1,len-1);<br>
  gotoxy(13,13);printf(&quot; &quot;);}<br>
  gotoxy(13,13);printf(&quot;%s&quot;,chmoney);ch[0]=getch();}<br>
  if((strlen(chshop)==0)||(strlen(chmoney)==0))<br>
  continue;<br>
  if((fp=fopen(&quot;home.dat&quot;,&quot;a+&quot;))!=NULL);<br>
  fprintf(fp,&quot;%10s%14s%6s&quot;,chtime,chshop,chmoney);<br>
  fputc('\n',fp);<br>
  fclose(fp);<br>
  i++;<br>
  gotoxy(41,5+i);<br>
  printf(&quot;%10s %-14s %-6s&quot;,chtime,chshop,chmoney);<br>
  }}} <br>
  ==============================================================<br>
  <font color="#990000">【程序96】</font><br>
  题目:计算字符串中子串出现的次数<br>
  1.程序分析:<br>
  2.程序源代码:<br>
  #include &quot;string.h&quot;<br>
  #include &quot;stdio.h&quot;<br>
  main()<br>
  { char str1[20],str2[20],*p1,*p2;<br>
  int sum=0;<br>
  printf(&quot;please input two strings\n&quot;);<br>
  scanf(&quot;%s%s&quot;,str1,str2);<br>
  p1=str1;p2=str2;<br>
  while(*p1!='\0')<br>
  {<br>
  if(*p1==*p2)<br>
  {while(*p1==*p2&amp;&amp;*p2!='\0')<br>
  {p1++;<br>
  p2++;}<br>
  }<br>
  else<br>
  p1++;<br>
  if(*p2=='\0')<br>
  sum++;<br>
  p2=str2;<br>
  }<br>
  printf(&quot;%d&quot;,sum);<br>
  getch();} <br>
  ==============================================================<br>
  <font color="#990000">【程序97】</font><br>
  题目:从键盘输入一些字符,逐个把它们送到磁盘上去,直到输入一个#为止。<br>
  1.程序分析:     <br>
  2.程序源代码:<br>
  #include &quot;stdio.h&quot;<br>
  main()<br>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -