?? 06年3月29日_經典c程序(16-20)_老古開發網文章.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0032)http://www.laogu.com/wz_1387.htm -->
<HTML><HEAD><TITLE>06年3月29日_經典c程序(16/20)_老古開發網文章</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content=經典c程序(16/20) name=keywords>
<META content=有關經典c程序(16/20)的新聞和技術文章 name=description><LINK
href="06年3月29日_經典c程序(16-20)_老古開發網文章.files/category.css" type=text/css
rel=stylesheet>
<META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD>
<BODY vLink=#0000ff bgColor=#ffffff leftMargin=5 topMargin=5>
<DIV align=center>
<TABLE class=tableMain width=736 align=center border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=2 cellPadding=2 width=728 align=center bgColor=#fdfce8
border=0>
<TBODY>
<TR>
<TD width=290>
<DIV align=left><A
href="http://www.zlgmcu.com/tools/LogicAnalyser/LA-logic.asp"
target=_blank><IMG height=60
src="06年3月29日_經典c程序(16-20)_老古開發網文章.files/zlg.gif" width=290
border=0></A></DIV></TD>
<TD width=146>
<DIV align=center><A href="http://www.laogu.com/GUANGGAO.HTM"
target=_blank>整站廣告招商</A></DIV></TD>
<TD width=125>
<DIV align=center><A href="http://www.jdisplay.net/"
target=_blank><IMG height=60
src="06年3月29日_經典c程序(16-20)_老古開發網文章.files/chengqi.gif" width=140
border=0></A></DIV></TD>
<TD width=149>
<DIV align=right><A
href="http://www.techshine.com/peixun/peixun.asp" target=_blank><IMG
height=60 src="06年3月29日_經典c程序(16-20)_老古開發網文章.files/techshine.gif"
width=140 border=0></A></DIV></TD></TR>
<TR>
<TD><A href="http://www.eflagtech.com/" target=_blank><IMG height=60
src="06年3月29日_經典c程序(16-20)_老古開發網文章.files/yiqisite.gif" width=290
border=0></A></TD>
<TD><A href="http://www.laogu.com/GUANGGAO.HTM" target=_blank><IMG
height=60 src="06年3月29日_經典c程序(16-20)_老古開發網文章.files/quanzhan.gif"
width=140 border=0></A></TD>
<TD> </TD>
<TD>
<DIV align=right></DIV></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE class=tableMain cellSpacing=0 cellPadding=0 width=736 align=center
border=0>
<TBODY>
<TR>
<TD>
<SCRIPT type=text/javascript><!--
google_ad_client = "pub-1420557601534669";
google_ad_width = 728;
google_alternate_ad_url = "http://www.laogu.com/my/welcome.gif";
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "93c901";
google_color_url = "000000";
//--></SCRIPT>
<SCRIPT src="06年3月29日_經典c程序(16-20)_老古開發網文章.files/show_ads.js"
type=text/javascript>
</SCRIPT>
</TD></TR>
<TR>
<TD></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=736 bgColor=#93c901 border=0>
<TBODY>
<TR>
<TD width=160 bgColor=#ffffcc height=2>
<DIV align=left><A href="http://www.laogu.com/article.aspx"><IMG height=70
src="06年3月29日_經典c程序(16-20)_老古開發網文章.files/xinwen.gif" width=160
border=0></A></DIV></TD>
<TD width="80%" bgColor=#ffffcc height=2>
<TABLE height=70 width=390 align=center bgColor=#fdfce8 border=0>
<TBODY>
<TR>
<TD width=284>
<DIV align=center><A
href="http://www.eetchina.com/STATIC/SITE/WEBINAR.HTM?sources=3rdpartners"
target=_blank><IMG height=60
src="06年3月29日_經典c程序(16-20)_老古開發網文章.files/EDC_THC_banner_laogu.gif"
width=400 border=0></A></DIV></TD>
<TD width=41>
<DIV align=right></DIV></TD></TR></TBODY></TABLE></TD>
<TD width=156 bgColor=#ffffcc>
<DIV align=right><A href="http://www.laogu.com/"><IMG height=70
alt=老古開發網首頁 src="06年3月29日_經典c程序(16-20)_老古開發網文章.files/newhome.gif"
width=156 border=0></A></DIV></TD></TR></TBODY></TABLE>
<TABLE class=tableMain cellSpacing=1 cellPadding=3 width=736 border=0>
<TBODY>
<TR>
<TD vAlign=top bgColor=#ffffff colSpan=2>
<DIV class=s10 align=center>
<DIV align=center></DIV>
<DIV align=center></DIV></DIV>
<DIV align=center>
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" align=center
border=0 valign="top">
<TBODY>
<TR>
<TD align=left height=25><STRONG><BR>導航:</STRONG><A
href="http://www.laogu.com/">老古開發網首頁</A>→<A
href="http://www.laogu.com/article.aspx">文章分類</A>→<A
href="http://www.laogu.com/ctg_6.htm">單片機</A>→<A
href="http://www.laogu.com/ctg_6_16.htm">第16頁</A>→[<FONT
color=#004800>經典c程序(16/20)</FONT>] <BR>| -<A
href="http://www.laogu.com/searchnews.aspx" target=_blank>文章搜索</A> -
<A href="http://www.laogu.com/articlenew.aspx"
target=_blank>最新文章</A> - | <BR>
<DIV align=center>
<H3>第1387篇:經典c程序(16/20)</H3></DIV></TD></TR>
<TR>
<TD class=table vAlign=top bgColor=#ffffff>發布時間:2006年3月28日
<BR>點擊次數:71 <BR>
<TABLE class=rcontent cellSpacing=0 width="100%" bgColor=#93c901
border=1>
<TBODY>
<TR>
<TD></TD></TR></TBODY></TABLE>詳細內容:經典c程序(16/20)<BR><BR>
<P>題目:求1+2!+3!+...+20!的和<BR>1.程序分析:此程序只是把累加變成了累乘。
<BR>2.程序源代碼:<BR>main()<BR>{<BR>float
n,s=0,t=1;<BR>for(n=1;n<=20;n++)<BR> {<BR> t*=n;<BR> s+=t;<BR> }<BR>printf("1+2!+3!...+20!=%e\n",s);<BR>}<BR></P>
<P>題目:有一分數序列:2/1,3/2,5/3,8/5,13/8,21/13...求出這個數列的前20項之和。<BR>1.程序分析:請抓住分子與分母的變化規律。
<BR>2.程序源代碼:<BR>main()<BR>{<BR>int n,t,number=20;<BR>float
a=2,b=1,s=0;<BR>for(n=1;n<=number;n++)<BR> {<BR> s=s+a/b;<BR> t=a;a=a+b;b=t;/*這部分是程序的關鍵,請讀者猜猜t的作用*/<BR> }<BR>printf("sum
is %9.6f\n",s);<BR>}</P>
<P>題目:打印出如下圖案(菱形) </P>
<P>*<BR>***<BR>******<BR>********<BR>******<BR>***<BR>*<BR>1.程序分析:先把圖形分成兩部分來看待,前四行一個規律,后三行一個規律,利用雙重<BR> for循環,第一層控制行,第二層控制列。
<BR>2.程序源代碼:<BR>main()<BR>{<BR>int
i,j,k;<BR>for(i=0;i<=3;i++)<BR> {<BR> for(j=0;j<=2-i;j++)<BR> printf("
");<BR> for(k=0;k<=2*i;k++)<BR> printf("*");<BR> printf("\n");<BR> }<BR>for(i=0;i<=2;i++)<BR> {<BR> for(j=0;j<=i;j++)<BR> printf("
");<BR> for(k=0;k<=4-2*i;k++)<BR> printf("*");<BR> printf("\n");<BR> }<BR>}<BR></P>
<P>
<TABLE cellSpacing=0 cellPadding=0 width="94%" align=center
border=0>
<TBODY>
<TR>
<TD><FONT
color=#000000>題目:兩個乒乓球隊進行比賽,各出三人。甲隊為a,b,c三人,乙隊為x,y,z三人。已抽簽決定<BR> 比賽名單。有人向隊員打聽比賽的名單。a說他不和x比,c說他不和x,z比,請編程序找出<BR> 三隊賽手的名單。
<BR>1.程序分析:判斷素數的方法:用一個數分別去除2到sqrt(這個數),如果能被整除,<BR> 則表明此數不是素數,反之是素數。
<BR>2.程序源代碼:<BR>main()<BR>{<BR>char
i,j,k;/*i是a的對手,j是b的對手,k是c的對手*/<BR>for(i=''x'';i<=''z'';i++)<BR> for(j=''x'';j<=''z'';j++)<BR> {<BR> if(i!=j)<BR> for(k=''x'';k<=''z'';k++)<BR> {
if(i!=k&&j!=k)<BR> {
if(i!=''x''&&k!=''x''&&k!=''z'')<BR> printf("order
is
a--%c\tb--%c\tc--%c\n",i,j,k);<BR> }<BR> }<BR> }<BR>}<BR></FONT></TD></TR></TBODY></TABLE></P>
<P>題目:猴子吃桃問題:猴子第一天摘下若干個桃子,當即吃了一半,還不癮,又多吃了一個<BR> 第二天早上又將剩下的桃子吃掉一半,又多吃了一個。以后每天早上都吃了前一天剩下<BR> 的一半零一個。到第10天早上想再吃時,見只剩下一個桃子了。求第一天共摘了多少。<BR>1.程序分析:采取逆向思維的方法,從后往前推斷。<BR>2.程序源代碼:<BR>main()<BR>{<BR>int
day,x1,x2;<BR>day=9;<BR>x2=1;<BR>while(day>0)<BR> {x1=(x2+1)*2;/*第一天的桃子數是第2天桃子數加1后的2倍*/<BR> x2=x1;<BR> day--;<BR> }<BR>printf("the
total is %d\n",x1);<BR>}<BR></P>
<DIV align=left>
<P><BR></P>
<P><FONT color=#ff0000>歡迎進入<A href="http://www.laogu.com/laogubbs/"
_target="_blank">老古論壇</A>對經典c程序(16/20)進行討論<BR></FONT></P></DIV><BR></TD>
<TR>
<TD class=table vAlign=top bgColor=#ffffff></TD>
<TR>
<TD class=table vAlign=top bgColor=#ffffff></TD>
<TR>
<TD>上一個:<A
href="http://www.laogu.com/wz_1388.htm">經典c程序(17/20)</A></TD></TR>
<TR>
<TD>下一個:<A
href="http://www.laogu.com/wz_1386.htm">經典c程序(15/20)</A></TD></TR>
<TR>
<TD class=date vAlign=top
bgColor=#ffffff></TD></TR></TBODY></TABLE></DIV></TD></TR></TBODY></TABLE></DIV>
<DIV align=center><A href="http://www.laogu.com/">老古開發網</A>版權所有 2005年11月 asp.Net
設計:<A href="http://www.laogu.com/">老古</A>,<BR>2006-3-29 15:54:17 頁面緩存:否 125毫秒
</DIV></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -