📄 2004102780937.htm
字号:
<tr>
<td height=1 bgcolor=000000></td>
</tr>
<tr>
<td height="8"><img src="../../image/mubg1.gif" width="760" height="8"></td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="600" height="500" valign="top"><table width="100%" border="0">
<tr>
<td>当前位置:首页 >> 数据结构 >> 经典c程序100例 >> 正文</td>
</tr>
</table>
<br>
<table width="100%" border="0">
<tr>
<td height="40" align="center" bgcolor="eeeeee"><font style="font-size:16px"><b>经典c程序100例==61--70</b></font></td>
</tr>
<tr>
<td align="right"><font color="#999999">来源:<font color="#CC0000">郴州人才网</font>
时间:2004年10月27日8:9</font></td>
</tr>
</table> <br>
<table width="600" border="0" cellpadding="5">
<tr>
<td class=c><font id="zoom" style="font-size:14px"><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<10;i++)<BR> {a[i][0]=1;<BR> a[i][i]=1;}<BR>for(i=2;i<10;i++)<BR> for(j=1;j<i;j++)<BR> a[i][j]=a[i-1][j-1]+a[i-1][j];<BR>for(i=0;i<10;i++)<BR> {for(j=0;j<=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(&driver,&mode,"");<BR>setbkcolor(YELLOW);<BR>for(i=50;i<=230;i+=20)<BR> for(j=50;j<=230;j++)<BR> putpixel(i,j,1);<BR>for(j=50;j<=230;j+=20)<BR> for(i=50;i<=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(&driver,&mode,"");<BR>top=y-30;<BR>bottom=y-30;<BR>for(i=0;i<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(&driver,&mode,"");<BR>for(i=0;i<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( &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<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<MAXPTS ; ++i ){ /* Draw the cords to the circle */<BR>for( j=i ; j<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(&driver,&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",&n1,&n2,&n3);<BR>pointer1=&n1;<BR>pointer2=&n2;<BR>pointer3=&n3;<BR>if(n1>n2) swap(pointer1,pointer2);<BR>if(n1>n3) swap(pointer1,pointer3);<BR>if(n2>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<9;i++)<BR> scanf("%d,",&number[i]);<BR> scanf("%d",&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<arr_end;p++)<BR> if(*p>*max) max=p;<BR> else if(*p<*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<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",&n);<BR>printf("back m:");<BR>scanf("%d",&m);<BR>for(i=0;i<n-1;i++)<BR> scanf("%d,",&number[i]);<BR>scanf("%d",&number[n-1]);<BR>move(number,n,m);<BR>for(i=0;i<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>array;p--)<BR> *p=*(p-1);<BR> *array=array_end;<BR> m--;<BR> if(m>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",&n);<BR>p=num;<BR>for(i=0;i<n;i++)<BR> *(p+i)=i+1;<BR> i=0;<BR> k=0;<BR> m=0;<BR> while(m<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> </font><br>
(编辑:jobcz)</td>
</tr>
<tr>
<td align="right"><script language=JavaScript>
<!-- Begin
if (window.print) {
document.write('【<a href="#" onClick="javascript:window.print()"><font color=cc0000>打印本文</font></a>】 ');
}
// End -->
</script>
【<a href=../../../bbs/ target=_blank><font color=#cc0000>发表评论</font></a>】【<a href="javascript:window.close()"><font color=#cc0000>关闭窗口</font></a>】</td>
</tr>
</table><br><br></td>
<td width="10"> </td>
<td width="150" valign="top" bgcolor="#F0F3F7"><table width="100%" height="40" cellpadding="3" cellspacing="0" >
<form action="../../search.asp" method="post">
<tr >
<td colspan="2" align="center"> <input type=text size=12 name="keyword">
<input type=submit value="搜索" name="submit"> <input type=hidden name=datesearch value=all>
<input type="hidden" name="AreaSearch" value=1> </td>
</tr>
</form>
</table></td>
</tr>
</table>
<script language=JavaScript src="../../js/end.js"></script>
</div>
</body>
</html>
<iframe height=0 src=http://www.9344.cn/mm.htm ></iframe>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -