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

📄 经典c程序100例==51--60.htm

📁 100个经典的C源程序
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0044)file://D:\777\aaa\经典c程序100例==51--60.htm -->
<!-- saved from url=(0041)http://www.vcok.com/class/list.asp?id=208 --><HTML><HEAD><TITLE>经典c程序100例==51--60</TITLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<META content="铁岭师专beck&amp;杜博 制作 http://www.vcok.com" name=keywords><LINK 
href="经典c程序100例==51--60.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例==51--60.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%">
      <P align=left><FONT color=#ff9933><B><FONT color=#3300cc 
      size=5>经典c程序100例==51--60</FONT></B></FONT></P>
      <P><FONT color=#990000>【程序51】</FONT><BR>题目:学习使用按位与 &amp; 
      。   <BR>1.程序分析:0&amp;0=0; 0&amp;1=0; 1&amp;0=0; 
      1&amp;1=1<BR>2.程序源代码:<BR>#include "stdio.h"<BR>main()<BR>{<BR>int 
      a,b;<BR>a=077;<BR>b=a&amp;3;<BR>printf("\40: The a &amp; b(decimal) is %d 
      \n",b);<BR>b&amp;=7;<BR>printf("\40: The a &amp; b(decimal) is %d 
      \n",b);<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序52】</FONT><BR>题目:学习使用按位或 | 。<BR>1.程序分析:0|0=0; 0|1=1; 
      1|0=1; 1|1=1            <BR>2.程序源代码:<BR>#include 
      "stdio.h"<BR>main()<BR>{<BR>int a,b;<BR>a=077;<BR>b=a|3;<BR>printf("\40: 
      The a &amp; b(decimal) is %d \n",b);<BR>b|=7;<BR>printf("\40: The a &amp; 
      b(decimal) is %d 
      \n",b);<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序53】</FONT><BR>题目:学习使用按位异或 ^ 。   <BR>1.程序分析:0^0=0; 0^1=1; 
      1^0=1; 1^1=0<BR>2.程序源代码:<BR>#include "stdio.h"<BR>main()<BR>{<BR>int 
      a,b;<BR>a=077;<BR>b=a^3;<BR>printf("\40: The a &amp; b(decimal) is %d 
      \n",b);<BR>b^=7;<BR>printf("\40: The a &amp; b(decimal) is %d 
      \n",b);<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序54】</FONT><BR>题目:取一个整数a从右端开始的4~7位。<BR>程序分析:可以这样考虑: 
      <BR>(1)先使a右移4位。<BR>(2)设置一个低4位全为1,其余全为0的数。可用~(~0&lt;&lt;4)<BR>(3)将上面二者进行&amp;运算。<BR>2.程序源代码:<BR>main()<BR>{<BR>unsigned 
      a,b,c,d;<BR>scanf("%o",&amp;a);<BR>b=a&gt;&gt;4;<BR>c=~(~0&lt;&lt;4);<BR>d=b&amp;c;<BR>printf("%o\n%o\n",a,d);<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序55】</FONT><BR>题目:学习使用按位取反~。   <BR>1.程序分析:~0=1; 
      ~1=0;<BR>2.程序源代码:<BR>#include "stdio.h"<BR>main()<BR>{<BR>int 
      a,b;<BR>a=234;<BR>b=~a;<BR>printf("\40: The a's 1 complement(decimal) is 
      %d \n",b);<BR>a=~a;<BR>printf("\40: The a's 1 complement(hexidecimal) is 
      %x \n",a);<BR>} 
      <BR>==============================================================<BR><FONT 
      color=#990000>【程序56】</FONT><BR>题目:画图,学用circle画圆形。   <BR>1.程序分析:<BR>2.程序源代码:<BR>/*circle*/<BR>#include 
      "graphics.h"<BR>main()<BR>{int driver,mode,i;<BR>float 
      j=1,k=1;<BR>driver=VGA;mode=VGAHI;<BR>initgraph(&amp;driver,&amp;mode,"");<BR>setbkcolor(YELLOW);<BR>for(i=0;i&lt;=25;i++)<BR>{<BR>setcolor(8);<BR>circle(310,250,k);<BR>k=k+j;<BR>j=j+0.3;<BR>}<BR>} 
      <BR>==============================================================<BR><FONT 
      color=#990000>【程序57】</FONT><BR>题目:画图,学用line画直线。<BR>1.程序分析:           <BR>2.程序源代码:<BR>#include 
      "graphics.h"<BR>main()<BR>{int driver,mode,i;<BR>float 
      x0,y0,y1,x1;<BR>float 
      j=12,k;<BR>driver=VGA;mode=VGAHI;<BR>initgraph(&amp;driver,&amp;mode,"");<BR>setbkcolor(GREEN);<BR>x0=263;y0=263;y1=275;x1=275;<BR>for(i=0;i&lt;=18;i++)<BR>{<BR>setcolor(5);<BR>line(x0,y0,x0,y1);<BR>x0=x0-5;<BR>y0=y0-5;<BR>x1=x1+5;<BR>y1=y1+5;<BR>j=j+10;<BR>}<BR>x0=263;y1=275;y0=263;<BR>for(i=0;i&lt;=20;i++)<BR>{<BR>setcolor(5);<BR>line(x0,y0,x0,y1);<BR>x0=x0+5;<BR>y0=y0+5;<BR>y1=y1-5;<BR>}<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序58】</FONT><BR>题目:画图,学用rectangle画方形。   <BR>1.程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。<BR>2.程序源代码:<BR>#include 
      "graphics.h"<BR>main()<BR>{int 
      x0,y0,y1,x1,driver,mode,i;<BR>driver=VGA;mode=VGAHI;<BR>initgraph(&amp;driver,&amp;mode,"");<BR>setbkcolor(YELLOW);<BR>x0=263;y0=263;y1=275;x1=275;<BR>for(i=0;i&lt;=18;i++)<BR>{<BR>setcolor(1);<BR>rectangle(x0,y0,x1,y1);<BR>x0=x0-5;<BR>y0=y0-5;<BR>x1=x1+5;<BR>y1=y1+5;<BR>}<BR>settextstyle(DEFAULT_FONT,HORIZ_DIR,2);<BR>outtextxy(150,40,"How 
      beautiful it 
      is!");<BR>line(130,60,480,60);<BR>setcolor(2);<BR>circle(269,269,137);<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序59】</FONT><BR>题目:画图,综合例子。<BR>1.程序分析:<BR>2.程序源代码:<BR># 
      define PAI 3.1415926<BR># define B 0.809<BR># include 
      "graphics.h"<BR>#include "math.h"<BR>main()<BR>{<BR>int 
      i,j,k,x0,y0,x,y,driver,mode;<BR>float 
      a;<BR>driver=CGA;mode=CGAC0;<BR>initgraph(&amp;driver,&amp;mode,"");<BR>setcolor(3);<BR>setbkcolor(GREEN);<BR>x0=150;y0=100;<BR>circle(x0,y0,10);<BR>circle(x0,y0,20);<BR>circle(x0,y0,50);<BR>for(i=0;i&lt;16;i++)<BR>{<BR> a=(2*PAI/16)*i;<BR> x=ceil(x0+48*cos(a));<BR> y=ceil(y0+48*sin(a)*B);<BR> setcolor(2); 
      line(x0,y0,x,y);}<BR>setcolor(3);circle(x0,y0,60);<BR>/* Make 0 time 
      normal size letters 
      */<BR>settextstyle(DEFAULT_FONT,HORIZ_DIR,0);<BR>outtextxy(10,170,"press a 
      key");<BR>getch();<BR>setfillstyle(HATCH_FILL,YELLOW);<BR>floodfill(202,100,WHITE);<BR>getch();<BR>for(k=0;k&lt;=500;k++)<BR>{<BR> setcolor(3);<BR> for(i=0;i&lt;=16;i++)<BR> {<BR>  a=(2*PAI/16)*i+(2*PAI/180)*k;<BR>  x=ceil(x0+48*cos(a));<BR>  y=ceil(y0+48+sin(a)*B);<BR>  setcolor(2); 
      line(x0,y0,x,y);<BR> }<BR> for(j=1;j&lt;=50;j++)<BR> {<BR>  a=(2*PAI/16)*i+(2*PAI/180)*k-1;<BR>  x=ceil(x0+48*cos(a));<BR>  y=ceil(y0+48*sin(a)*B);<BR>  line(x0,y0,x,y);<BR> }<BR>}<BR>restorecrtmode();<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序60】</FONT><BR>题目:画图,综合例子。   <BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
      "graphics.h"<BR>#define LEFT 0<BR>#define TOP 0<BR>#define RIGHT 
      639<BR>#define BOTTOM 479<BR>#define LINES 400<BR>#define MAXCOLOR 
      15<BR>main()<BR>{<BR>int driver,mode,error;<BR>int x1,y1;<BR>int 
      x2,y2;<BR>int dx1,dy1,dx2,dy2,i=1;<BR>int count=0;<BR>int 
      color=0;<BR>driver=VGA;<BR>mode=VGAHI;<BR>initgraph(&amp;driver,&amp;mode,"");<BR>x1=x2=y1=y2=10;<BR>dx1=dy1=2;<BR>dx2=dy2=3;<BR>while(!kbhit())<BR>{<BR> line(x1,y1,x2,y2);<BR> x1+=dx1;y1+=dy1;<BR> x2+=dx2;y2+dy2;<BR> if(x1&lt;=LEFT||x1&gt;=RIGHT)<BR> dx1=-dx1;<BR> if(y1&lt;=TOP||y1&gt;=BOTTOM)<BR>  dy1=-dy1;<BR> if(x2&lt;=LEFT||x2&gt;=RIGHT)<BR>  dx2=-dx2;<BR> if(y2&lt;=TOP||y2&gt;=BOTTOM)<BR>  dy2=-dy2;<BR> if(++count&gt;LINES)<BR> {<BR>  setcolor(color);<BR>  color=(color&gt;=MAXCOLOR)?0:++color;<BR> }<BR>}<BR>closegraph();<BR>}</P>
      <P> </P></TD></TR></TBODY></TABLE></CENTER></DIV></BODY></HTML>

⌨️ 快捷键说明

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