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

📄 经典c程序100例==41--50.htm

📁 100个经典的C源程序
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0044)file://D:\777\aaa\经典c程序100例==41--50.htm -->
<!-- saved from url=(0041)http://www.vcok.com/class/list.asp?id=207 --><HTML><HEAD><TITLE>经典c程序100例==41--50</TITLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<META content="铁岭师专beck&amp;杜博 制作 http://www.vcok.com" name=keywords><LINK 
href="经典c程序100例==41--50.files/new.css" rel=stylesheet>
<STYLE>.skin0 {
	BORDER-RIGHT: black 2px solid; BORDER-TOP: black 2px solid; VISIBILITY: hidden; BORDER-LEFT: black 2px solid; WIDTH: 130px; CURSOR: default; LINE-HEIGHT: 20px; BORDER-BOTTOM: black 2px solid; FONT-FAMILY: Verdana; POSITION: absolute; BACKGROUND-COLOR: menu; TEXT-ALIGN: left
}
.skin1 {
	BORDER-RIGHT: buttonhighlight 2px outset; BORDER-TOP: buttonhighlight 2px outset; FONT-SIZE: 9pt; VISIBILITY: hidden; BORDER-LEFT: buttonhighlight 2px outset; WIDTH: 110px; CURSOR: default; BORDER-BOTTOM: buttonhighlight 2px outset; FONT-FAMILY: 宋体, Arial, Helvetica, sans-serif; POSITION: absolute; BACKGROUND-COLOR: menu; TEXT-ALIGN: left
}
.menuitems {
	PADDING-RIGHT: 10px; PADDING-LEFT: 15px
}
</STYLE>

<STYLE type=text/css>TD {
	FONT-SIZE: 9pt
}
BODY {
	FONT-SIZE: 9pt; COLOR: #000000; 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>

<META http-equiv=Content-Type content="text/html; charset=gb2312">
<SCRIPT language=JavaScript>
<!--
var text=">>>> [ w w w . v c o k . c o m ] <<<< "
  var speed2=180
  var x=0
  function s2b()
  {var a=text.substring(0,x)
   var b=text.substring(x,x+1).toUpperCase()
   var c=text.substring(x+1,text.length)
   window.status=a+b+c
   if(x==text.length){x=0}
   else{x++}setTimeout("s2b()",speed2)}
  s2b();
//-->
</SCRIPT>

<STYLE type=text/css>A.link-a:hover {
	COLOR: #f7f3f7; TEXT-DECORATION: none
}
A.link-a:visited {
	COLOR: #ffffff; TEXT-DECORATION: none
}
A.link-a:link {
	COLOR: #ffffff; TEXT-DECORATION: none
}
</STYLE>

<META content="Microsoft FrontPage 5.0" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff leftMargin=0 
background=经典c程序100例==41--50.files/bg.gif topMargin=0 
onload="MM_preloadImages('images/print2.png','images/save2.png','images/re_write2.gif','images/home2.png')">
<P> </P>
<DIV align=center>
<CENTER>
<TABLE id=AutoNumber1 style="BORDER-COLLAPSE: collapse" borderColor=#111111 
cellSpacing=0 cellPadding=0 width="80%" border=1>
  <TBODY>
  <TR>
    <TD width="100%"><FONT color=#ff9933><B><FONT color=#3300cc 
      size=5>经典c程序100例==41--50</FONT></B></FONT>
      <P><FONT 
      color=#990000>【程序41】</FONT><BR>题目:学习static定义静态变量的用法   <BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
      "stdio.h"<BR>varfunc()<BR>{<BR>int var=0;<BR>static int 
      static_var=0;<BR>printf("\40:var equal %d \n",var);<BR>printf("\40:static 
      var equal %d 
      \n",static_var);<BR>printf("\n");<BR>var++;<BR>static_var++;<BR>}<BR>void 
      main()<BR>{int 
      i;<BR> for(i=0;i&lt;3;i++)<BR>  varfunc();<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序42】</FONT> 
      <BR>题目:学习使用auto定义变量的用法<BR>1.程序分析:      <BR>2.程序源代码:<BR>#include 
      "stdio.h"<BR>main()<BR>{int i,num;<BR>num=2;<BR> for 
      (i=0;i&lt;3;i++)<BR> { printf("\40: The num equal %d 
      \n",num);<BR>  num++;<BR>  {<BR>  auto int num=1;<BR>  printf("\40: The 
      internal block num equal %d 
      \n",num);<BR>  num++;<BR>  }<BR> }<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序43】</FONT><BR>题目:学习使用static的另一用法。   <BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
      "stdio.h"<BR>main()<BR>{<BR>int 
      i,num;<BR>num=2;<BR>for(i=0;i&lt;3;i++)<BR>{<BR>printf("\40: The num equal 
      %d \n",num);<BR>num++;<BR>{<BR>static int num=1;<BR>printf("\40:The 
      internal block num equal 
      %d\n",num);<BR>num++;<BR>}<BR>}<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序44】</FONT><BR>题目:学习使用external的用法。<BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
      "stdio.h"<BR>int a,b,c;<BR>void add()<BR>{ int 
      a;<BR>a=3;<BR>c=a+b;<BR>}<BR>void main()<BR>{ 
      a=b=4;<BR>add();<BR>printf("The value of c is equal to 
      %d\n",c);<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序45】</FONT><BR>题目:学习使用register定义变量的方法。<BR>1.程序分析:<BR>2.程序源代码:<BR>void 
      main()<BR>{<BR>register int i;<BR>int 
      tmp=0;<BR>for(i=1;i&lt;=100;i++)<BR>tmp+=i;<BR>printf("The sum is 
      %d\n",tmp);<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序46】</FONT><BR>题目:宏#define命令练习(1)   <BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
      "stdio.h"<BR>#define TRUE 1<BR>#define FALSE 0<BR>#define SQ(x) 
      (x)*(x)<BR>void main()<BR>{<BR>int num;<BR>int again=1;<BR>printf("\40: 
      Program will stop if input value less than 
      50.\n");<BR>while(again)<BR>{<BR>printf("\40:Please input 
      number==&gt;");<BR>scanf("%d",&amp;num);<BR>printf("\40:The square for 
      this number is %d 
      \n",SQ(num));<BR>if(num&gt;=50)<BR> again=TRUE;<BR>else<BR> again=FALSE;<BR>}<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序47】</FONT><BR>题目:宏#define命令练习(2)<BR>1.程序分析:            <BR>2.程序源代码:<BR>#include 
      "stdio.h"<BR>#define exchange(a,b) { \ 
      /*宏定义中允许包含两道衣裳命令的情形,此时必须在最右边加上"\"*/<BR>            int 
      t;\<BR>            t=a;\<BR>            a=b;\<BR>            b=t;\<BR>           }<BR>void 
      main(void)<BR>{<BR>int x=10;<BR>int y=20;<BR>printf("x=%d; 
      y=%d\n",x,y);<BR>exchange(x,y);<BR>printf("x=%d; 
      y=%d\n",x,y);<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序48】</FONT><BR>题目:宏#define命令练习(3)   <BR>1.程序分析:<BR>2.程序源代码:<BR>#define 
      LAG &gt;<BR>#define SMA &lt;<BR>#define EQ ==<BR>#include 
      "stdio.h"<BR>void main()<BR>{ int i=10;<BR>int j=20;<BR>if(i LAG 
      j)<BR>printf("\40: %d larger than %d \n",i,j);<BR>else if(i EQ 
      j)<BR>printf("\40: %d equal to %d \n",i,j);<BR>else if(i SMA 
      j)<BR>printf("\40:%d smaller than %d \n",i,j);<BR>else<BR>printf("\40: No 
      such 
      value.\n");<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序49】</FONT><BR>题目:#if #ifdef和#ifndef的综合应用。<BR>1. 程序分析: 
      <BR>2.程序源代码:<BR>#include "stdio.h"<BR>#define MAX<BR>#define MAXIMUM(x,y) 
      (x&gt;y)?x:y<BR>#define MINIMUM(x,y) (x&gt;y)?y:x<BR>void main()<BR>{ int 
      a=10,b=20;<BR>#ifdef MAX<BR>printf("\40: The larger one is 
      %d\n",MAXIMUM(a,b));<BR>#else<BR>printf("\40: The lower one is 
      %d\n",MINIMUM(a,b));<BR>#endif<BR>#ifndef MIN<BR>printf("\40: The lower 
      one is %d\n",MINIMUM(a,b));<BR>#else<BR>printf("\40: The larger one is 
      %d\n",MAXIMUM(a,b));<BR>#endif<BR>#undef MAX<BR>#ifdef MAX<BR>printf("\40: 
      The larger one is %d\n",MAXIMUM(a,b));<BR>#else<BR>printf("\40: The lower 
      one is %d\n",MINIMUM(a,b));<BR>#endif<BR>#define MIN<BR>#ifndef 
      MIN<BR>printf("\40: The lower one is 
      %d\n",MINIMUM(a,b));<BR>#else<BR>printf("\40: The larger one is 
      %d\n",MAXIMUM(a,b));<BR>#endif<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序50】</FONT><BR>题目:#include 
      的应用练习   <BR>1.程序分析:<BR>2.程序源代码:<BR>test.h 文件如下:<BR>#define LAG 
      &gt;<BR>#define SMA &lt;<BR>#define EQ ==<BR>#include "test.h" 
      /*一个新文件50.c,包含test.h*/<BR>#include "stdio.h"<BR>void main()<BR>{ int 
      i=10;<BR>int j=20;<BR>if(i LAG j)<BR>printf("\40: %d larger than %d 
      \n",i,j);<BR>else if(i EQ j)<BR>printf("\40: %d equal to %d 
      \n",i,j);<BR>else if(i SMA j)<BR>printf("\40:%d smaller than %d 
      \n",i,j);<BR>else<BR>printf("\40: No such value.\n");<BR>}</P>
      <P> </P></TD></TR></TBODY></TABLE></CENTER></DIV></BODY></HTML>

⌨️ 快捷键说明

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