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

📄 经典c程序100例==61--70.htm

📁 100个经典的C源程序
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0044)file://D:\777\aaa\经典c程序100例==61--70.htm -->
<!-- saved from url=(0041)http://www.vcok.com/class/list.asp?id=209 --><HTML><HEAD><TITLE>经典c程序100例==61--70</TITLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<META content="铁岭师专beck&amp;杜博 制作 http://www.vcok.com" name=keywords><LINK 
href="经典c程序100例==61--70.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例==61--70.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例==61--70</FONT></B></FONT>
      <P><FONT 
      color=#990000>【程序61】</FONT><BR>题目:打印出杨辉三角形(要求打印出10行如下图)   <BR>1.程序分析:<BR>    
         1<BR>      1  1<BR>      1  2  1<BR>      1  3  3  1<BR>      1  4  6 
       4  1<BR>      1  5  10 10 5  1  <BR>2.程序源代码:<BR>main()<BR>{int 
      i,j;<BR>int 
      a[10][10];<BR>printf("\n");<BR>for(i=0;i&lt;10;i++)<BR> {a[i][0]=1;<BR> a[i][i]=1;}<BR>for(i=2;i&lt;10;i++)<BR> for(j=1;j&lt;i;j++)<BR> a[i][j]=a[i-1][j-1]+a[i-1][j];<BR>for(i=0;i&lt;10;i++)<BR> {for(j=0;j&lt;=i;j++)<BR> printf("%5d",a[i][j]);<BR> printf("\n");<BR> }<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序62】</FONT><BR>题目:学习putpixel画点。<BR>1.程序分析:            <BR>2.程序源代码:<BR>#include 
      "stdio.h"<BR>#include "graphics.h"<BR>main()<BR>{<BR>int 
      i,j,driver=VGA,mode=VGAHI;<BR>initgraph(&amp;driver,&amp;mode,"");<BR>setbkcolor(YELLOW);<BR>for(i=50;i&lt;=230;i+=20)<BR> for(j=50;j&lt;=230;j++)<BR> putpixel(i,j,1);<BR>for(j=50;j&lt;=230;j+=20)<BR> for(i=50;i&lt;=230;i++)<BR> putpixel(i,j,1);<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序63】</FONT><BR>题目:画椭圆ellipse   <BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
      "stdio.h"<BR>#include "graphics.h"<BR>#include 
      "conio.h"<BR>main()<BR>{<BR>int x=360,y=160,driver=VGA,mode=VGAHI;<BR>int 
      num=20,i;<BR>int 
      top,bottom;<BR>initgraph(&amp;driver,&amp;mode,"");<BR>top=y-30;<BR>bottom=y-30;<BR>for(i=0;i&lt;num;i++)<BR>{<BR>ellipse(250,250,0,360,top,bottom);<BR>top-=5;<BR>bottom+=5;<BR>}<BR>getch();<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序64】</FONT><BR>题目:利用ellipse and rectangle 
      画图。<BR>1.程序分析:<BR>2.程序源代码:<BR>#include "stdio.h"<BR>#include 
      "graphics.h"<BR>#include "conio.h"<BR>main()<BR>{<BR>int 
      driver=VGA,mode=VGAHI;<BR>int i,num=15,top=50;<BR>int 
      left=20,right=50;<BR>initgraph(&amp;driver,&amp;mode,"");<BR>for(i=0;i&lt;num;i++)<BR>{<BR>ellipse(250,250,0,360,right,left);<BR>ellipse(250,250,0,360,20,top);<BR>rectangle(20-2*i,20-2*i,10*(i+2),10*(i+2));<BR>right+=5;<BR>left+=5;<BR>top+=10;<BR>}<BR>getch();<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序65】</FONT><BR>题目:一个最优美的图案。   <BR>1.程序分析:<BR>2.程序源代码:<BR>#include 
      "graphics.h"<BR>#include "math.h"<BR>#include "dos.h"<BR>#include 
      "conio.h"<BR>#include "stdlib.h"<BR>#include "stdio.h"<BR>#include 
      "stdarg.h"<BR>#define MAXPTS 15<BR>#define PI 3.1415926<BR>struct PTS 
      {<BR>int x,y;<BR>};<BR>double AspectRatio=0.85;<BR>void 
      LineToDemo(void)<BR>{<BR>struct viewporttype vp;<BR>struct PTS 
      points[MAXPTS];<BR>int i, j, h, w, xcenter, ycenter;<BR>int radius, angle, 
      step;<BR>double rads;<BR>printf(" MoveTo / LineTo Demonstration" 
      );<BR>getviewsettings( &amp;vp );<BR>h = vp.bottom - vp.top;<BR>w = 
      vp.right - vp.left;<BR>xcenter = w / 2; /* Determine the center of circle 
      */<BR>ycenter = h / 2;<BR>radius = (h - 30) / (AspectRatio * 2);<BR>step = 
      360 / MAXPTS; /* Determine # of increments */<BR>angle = 0; /* Begin at 
      zero degrees */<BR>for( i=0 ; i&lt;MAXPTS ; ++i ){ /* Determine circle 
      intercepts */<BR>rads = (double)angle * PI / 180.0; /* Convert angle to 
      radians */<BR>points[i].x = xcenter + (int)( cos(rads) * radius 
      );<BR>points[i].y = ycenter - (int)( sin(rads) * radius * AspectRatio 
      );<BR>angle += step; /* Move to next increment */<BR>}<BR>circle( xcenter, 
      ycenter, radius ); /* Draw bounding circle */<BR>for( i=0 ; i&lt;MAXPTS ; 
      ++i ){ /* Draw the cords to the circle */<BR>for( j=i ; j&lt;MAXPTS ; ++j 
      ){ /* For each remaining intersect */<BR>moveto(points[i].x, points[i].y); 
      /* Move to beginning of cord */<BR>lineto(points[j].x, points[j].y); /* 
      Draw the cord */<BR>} } }<BR>main()<BR>{int 
      driver,mode;<BR>driver=CGA;mode=CGAC0;<BR>initgraph(&amp;driver,&amp;mode,"");<BR>setcolor(3);<BR>setbkcolor(GREEN);<BR>LineToDemo();}<BR>==============================================================<BR><FONT 
      color=#990000>【程序66】</FONT><BR>题目:输入3个数a,b,c,按大小顺序输出。   <BR>1.程序分析:利用指针方法。<BR>2.程序源代码:<BR>/*pointer*/<BR>main()<BR>{<BR>int 
      n1,n2,n3;<BR>int *pointer1,*pointer2,*pointer3;<BR>printf("please input 3 
      number:n1,n2,n3:");<BR>scanf("%d,%d,%d",&amp;n1,&amp;n2,&amp;n3);<BR>pointer1=&amp;n1;<BR>pointer2=&amp;n2;<BR>pointer3=&amp;n3;<BR>if(n1&gt;n2) 
      swap(pointer1,pointer2);<BR>if(n1&gt;n3) 
      swap(pointer1,pointer3);<BR>if(n2&gt;n3) 
      swap(pointer2,pointer3);<BR>printf("the sorted numbers 
      are:%d,%d,%d\n",n1,n2,n3);<BR>}<BR>swap(p1,p2)<BR>int *p1,*p2;<BR>{int 
      p;<BR>p=*p1;*p1=*p2;*p2=p;<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序67】</FONT><BR>题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。<BR>1.程序分析:谭浩强的书中答案有问题。      <BR>2.程序源代码:<BR>main()<BR>{<BR>int 
      number[10];<BR>input(number);<BR>max_min(number);<BR>output(number);<BR>}<BR>input(number)<BR>int 
      number[10];<BR>{int 
      i;<BR>for(i=0;i&lt;9;i++)<BR> scanf("%d,",&amp;number[i]);<BR> scanf("%d",&amp;number[9]);<BR>}<BR>max_min(array)<BR>int 
      array[10];<BR>{int *max,*min,k,l;<BR>int 
      *p,*arr_end;<BR>arr_end=array+10;<BR>max=min=array;<BR>for(p=array+1;p&lt;arr_end;p++)<BR> if(*p&gt;*max) 
      max=p;<BR> else if(*p&lt;*min) 
      min=p;<BR> k=*max;<BR> l=*min;<BR> *p=array[0];array[0]=l;l=*p;<BR> *p=array[9];array[9]=k;k=*p;<BR> return;<BR>}<BR>output(array)<BR>int 
      array[10];<BR>{ int 
      *p;<BR>for(p=array;p&lt;array+9;p++)<BR> printf("%d,",*p);<BR>printf("%d\n",array[9]);<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序68】</FONT><BR>题目:有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数<BR>1.程序分析:<BR>2.程序源代码:<BR>main()<BR>{<BR>int 
      number[20],n,m,i;<BR>printf("the total numbers 
      is:");<BR>scanf("%d",&amp;n);<BR>printf("back 
      m:");<BR>scanf("%d",&amp;m);<BR>for(i=0;i&lt;n-1;i++)<BR> scanf("%d,",&amp;number[i]);<BR>scanf("%d",&amp;number[n-1]);<BR>move(number,n,m);<BR>for(i=0;i&lt;n-1;i++)<BR> printf("%d,",number[i]);<BR>printf("%d",number[n-1]);<BR>}<BR>move(array,n,m)<BR>int 
      n,m,array[20];<BR>{<BR>int 
      *p,array_end;<BR>array_end=*(array+n-1);<BR>for(p=array+n-1;p&gt;array;p--)<BR> *p=*(p-1);<BR> *array=array_end;<BR> m--;<BR> if(m&gt;0) 
      move(array,n,m);<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序69】</FONT><BR>题目:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出<BR>   圈子,问最后留下的是原来第几号的那位。<BR>1. 
      程序分析:<BR>2.程序源代码:<BR>#define nmax 50<BR>main()<BR>{<BR>int 
      i,k,m,n,num[nmax],*p;<BR>printf("please input the total of 
      numbers:");<BR>scanf("%d",&amp;n);<BR>p=num;<BR>for(i=0;i&lt;n;i++)<BR> *(p+i)=i+1;<BR> i=0;<BR> k=0;<BR> m=0;<BR> while(m&lt;n-1)<BR> {<BR> if(*(p+i)!=0) 
      k++;<BR> if(k==3)<BR> { 
      *(p+i)=0;<BR> k=0;<BR> m++;<BR> }<BR>i++;<BR>if(i==n) 
      i=0;<BR>}<BR>while(*p==0) p++;<BR>printf("%d is 
      left\n",*p);<BR>}<BR>==============================================================<BR><FONT 
      color=#990000>【程序70】</FONT><BR>题目:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。   <BR>1.程序分析:<BR>2.程序源代码:<BR>main()<BR>{<BR>int 
      len;<BR>char *str[20];<BR>printf("please input a 
      string:\n");<BR>scanf("%s",str);<BR>len=length(str);<BR>printf("the string 
      has %d characters.",len);<BR>}<BR>length(p)<BR>char *p;<BR>{<BR>int 
      n;<BR>n=0;<BR>while(*p!='\0')<BR>{<BR> n++;<BR> p++;<BR>}<BR>return 
      n;<BR>}</P>
      <P> </P></TD></TR></TBODY></TABLE></CENTER></DIV></BODY></HTML>

⌨️ 快捷键说明

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