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

📄 list4.htm

📁 经典一百例(c语言版)
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<div id="Layer2" style="position:absolute; width:19px; height:14px; z-index:2; left: 644px; top: 6px"> </div>
<TABLE cellSpacing=0 cellPadding=0 width=650 
align=center  >
  <TBODY> 
  <TR vAlign=center align=left>
    <TD background="images/titleback.png" colSpan=2 
    height=22 valign="top" width=650> 
      <TABLE cellSpacing=2 cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>
          <TD width=40 valign="top">&nbsp;</TD>
                      <TD class=zi width=562 valign="middle"><b><font color="#ffffff">.:.:经典c程序100例==31--40:.:.</font></b></TD>
          <TD class=zi width=18 valign="top">&nbsp;</TD>
          <TD width=16 valign="middle"><a href="javascript:window.close();" title=关闭窗口><img height=19 
            src="images/close.png" width=19 border=0></a></TD>
        </TR></TBODY></TABLE></TD></TR>
  <TR vAlign=center align=left>
    <TD bgColor=#BDCFF7 colSpan=2 height=24 valign="top" >
      <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 >
        <TBODY> 
        <TR> 
          <TD width=1 ></TD>
          <TD align=right width=24><a href="http://www.ie586.net" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image5','','images/home2.png',1)"><img name="Image5" border="0" src="images/home.png" width="24" height="22" title=返回页面></a></TD>
          <TD align=right width=24><a href="http://210.76.63.207/lb5000/leoboard.cgi" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image4','','images/re_write2.gif',1)"><img name="Image4" border="0" src="images/re_write.gif" width="20" height="19" title=发表评论></a></TD>
          <TD width=24> 
            <div align="center"><a href="#" onClick="window.print();return false"><img src="images/print.png" alt="打印文档" border="0" name="p" onMouseOver="MM_swapImage('p','','images/print2.png',1)" width="24" height="22"></a></div>
          </TD>
          <TD width=2 ></TD>
          <TD class=zi vAlign=center width=308 height=25><font size="2">&nbsp; 文字     
            <SELECT 
            style="WIDTH: 60px; HEIGHT: 20px; fontsize: 9pt" 
            onchange=setFontColor(this.value); name=seltextcolor>
              <OPTION 
              value=#000000 selected>黑色</OPTION>
              <OPTION 
              value=#FFFFFF>白色</OPTION>
              <OPTION value=#FF0000>红色</OPTION>
              <OPTION value=#555555>灰色</OPTION>
              <OPTION 
              value=#00FF00>绿色</OPTION>
              <OPTION value=#0000FF>蓝色</OPTION>
              <OPTION value=#00cccc>青色</OPTION>
              <OPTION 
            value=#ffff00>黄色</OPTION>
            </SELECT>
            背景     
            <SELECT 
            style="WIDTH: 60px; HEIGHT: 20px; fontsize: 9pt" 
            onchange=setBgColor(this.value); name=selbkcolor>
              <OPTION 
              value=#FFFFFF selected>白色</OPTION>
              <OPTION 
              value=#000000>黑色</OPTION>
              <OPTION value=#FFCCFF>粉红</OPTION>
              <OPTION value=#CCCCCC>灰色</OPTION>
              <OPTION 
              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">28944</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例==31--40</font></font></b></font></p>
<p><font color="#990000">【程序31】</font><br>
  题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续<br>
     判断第二个字母。<br>
  1.程序分析:用情况语句比较好,如果第一个字母一样,则判断用情况语句或if语句判断第二个字母。<br>
  2.程序源代码:<br>
  #include &lt;stdio.h&gt;<br>
  void main()<br>
  {<br>
  char letter;<br>
  printf(&quot;please input the first letter of someday\n&quot;);<br>
  while ((letter=getch())!='Y')/*当所按字母为Y时才结束*/<br>
  { switch (letter)<br>
  {case 'S':printf(&quot;please input second letter\n&quot;);<br>
       if((letter=getch())=='a')<br>
        printf(&quot;saturday\n&quot;);<br>
       else if ((letter=getch())=='u')<br>
           printf(&quot;sunday\n&quot;);<br>
         else printf(&quot;data error\n&quot;);<br>
       break;<br>
  case 'F':printf(&quot;friday\n&quot;);break;<br>
  case 'M':printf(&quot;monday\n&quot;);break;<br>
  case 'T':printf(&quot;please input second letter\n&quot;);<br>
       if((letter=getch())=='u')<br>
        printf(&quot;tuesday\n&quot;);<br>
       else if ((letter=getch())=='h')<br>
           printf(&quot;thursday\n&quot;);<br>
         else printf(&quot;data error\n&quot;);<br>
       break;<br>
  case 'W':printf(&quot;wednesday\n&quot;);break;<br>
  default: printf(&quot;data error\n&quot;);<br>
    }<br>
   }<br>
  }<br>
  ==============================================================<br>
  <font color="#990000">【程序32】</font><br>
  题目:Press any key to change color, do you want to try it. Please hurry up!<br>
  1.程序分析:            <br>
  2.程序源代码:<br>
  #include &lt;conio.h&gt;<br>
  void main(void)<br>
  {<br>
  int color;<br>
  for (color = 0; color &lt; 8; color++)<br>
   { <br>
   textbackground(color);/*设置文本的背景颜色*/<br>
   cprintf(&quot;This is color %d\r\n&quot;, color);<br>
   cprintf(&quot;Press any key to continue\r\n&quot;);<br>
   getch();/*输入字符看不见*/<br>
   }<br>
  }<br>
  ==============================================================<br>
  <font color="#990000">【程序33】</font><br>
  题目:学习gotoxy()与clrscr()函数   <br>
  1.程序分析:<br>
  2.程序源代码:<br>
  #include &lt;conio.h&gt;<br>
  void main(void)<br>
  {<br>
  clrscr();/*清屏函数*/<br>
  textbackground(2);<br>
  gotoxy(1, 5);/*定位函数*/<br>
  cprintf(&quot;Output at row 5 column 1\n&quot;);<br>
  textbackground(3);<br>
  gotoxy(20, 10);<br>
  cprintf(&quot;Output at row 10 column 20\n&quot;);<br>
  }<br>
  ==============================================================<br>
  <font color="#990000">【程序34】</font><br>
  题目:练习函数调用<br>
  1. 程序分析: <br>
  2.程序源代码:<br>
  #include &lt;stdio.h&gt;<br>
  void hello_world(void)<br>
  {<br>
  printf(&quot;Hello, world!\n&quot;);<br>
  }<br>
  void three_hellos(void)<br>
  {<br>
  int counter;<br>
  for (counter = 1; counter &lt;= 3; counter++)<br>
  hello_world();/*调用此函数*/<br>
  }<br>
  void main(void)<br>
  {<br>
  three_hellos();/*调用此函数*/<br>
  }<br>
  ==============================================================<br>
  <font color="#990000">【程序35】</font><br>
  题目:文本颜色设置<br>
  1.程序分析:<br>
  2.程序源代码:<br>
  #include &lt;conio.h&gt;<br>
  void main(void)<br>
  {<br>
  int color;<br>
  for (color = 1; color &lt; 16; color++)<br>
   {<br>
   textcolor(color);/*设置文本颜色*/<br>
   cprintf(&quot;This is color %d\r\n&quot;, color);<br>
   }<br>
  textcolor(128 + 15);<br>
  cprintf(&quot;This is blinking\r\n&quot;);<br>
  }<br>
  ==============================================================<br>
  <font color="#990000">【程序36】</font><br>
  题目:求100之内的素数   <br>
  1.程序分析:<br>
  2.程序源代码:<br>
  #include &lt;stdio.h&gt;<br>
  #include &quot;math.h&quot;<br>
  #define N 101<br>
  main()<br>
  {<br>
  int i,j,line,a[N];<br>
  for(i=2;i&lt;N;i++) a[i]=i;<br>
  for(i=2;i&lt;sqrt(N);i++)<br>
   for(j=i+1;j&lt;N;j++)<br>
   {<br>
    if(a[i]!=0&amp;&amp;a[j]!=0)<br>
    if(a[j]%a[i]==0)<br>
    a[j]=0;}<br>
  printf(&quot;\n&quot;);<br>
  for(i=2,line=0;i&lt;N;i++)<br>
  {<br>
   if(a[i]!=0)<br>
   {printf(&quot;%5d&quot;,a[i]);<br>
   line++;}<br>
   if(line==10)<br>
   {printf(&quot;\n&quot;);<br>
  line=0;}<br>
  }<br>
  }<br>
  ==============================================================<br>
  <font color="#990000">【程序37】</font><br>
  题目:对10个数进行排序<br>
  1.程序分析:可以利用选择法,即从后9个比较过程中,选择一个最小的与第一个元素交换,<br>
        下次类推,即用第二个元素与后8个进行比较,并进行交换。        <br>
  2.程序源代码:<br>
  #define N 10<br>
  main()<br>
  {int i,j,min,tem,a[N];<br>
  /*input data*/<br>
  printf(&quot;please input ten num:\n&quot;);<br>
  for(i=0;i&lt;N;i++)<br>
  {<br>
  printf(&quot;a[%d]=&quot;,i);<br>
  scanf(&quot;%d&quot;,&amp;a[i]);}<br>
  printf(&quot;\n&quot;);<br>
  for(i=0;i&lt;N;i++)<br>
  printf(&quot;%5d&quot;,a[i]);<br>
  printf(&quot;\n&quot;);<br>
  /*sort ten num*/<br>
  for(i=0;i&lt;N-1;i++)<br>
  {min=i;<br>
  for(j=i+1;j&lt;N;j++)<br>
  if(a[min]&gt;a[j]) min=j;<br>
  tem=a[i];<br>
  a[i]=a[min];<br>
  a[min]=tem;<br>
  }<br>
  /*output data*/<br>
  printf(&quot;After sorted \n&quot;);<br>
  for(i=0;i&lt;N;i++)<br>
  printf(&quot;%5d&quot;,a[i]);<br>
  }<br>
  ==============================================================<br>
  <font color="#990000">【程序38】</font><br>
  题目:求一个3*3矩阵对角线元素之和 <br>
  1.程序分析:利用双重for循环控制输入二维数组,再将a[i][i]累加后输出。<br>
  2.程序源代码:<br>
  main()<br>
  {<br>
  float a[3][3],sum=0;<br>
  int i,j;<br>

⌨️ 快捷键说明

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