![C語言程序設計教程_楊路明__課后習習題答案_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/26/8a3a7de9-1101-4199-bc3c-e66960f9cb67/8a3a7de9-1101-4199-bc3c-e66960f9cb671.gif)
![C語言程序設計教程_楊路明__課后習習題答案_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/26/8a3a7de9-1101-4199-bc3c-e66960f9cb67/8a3a7de9-1101-4199-bc3c-e66960f9cb672.gif)
![C語言程序設計教程_楊路明__課后習習題答案_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/26/8a3a7de9-1101-4199-bc3c-e66960f9cb67/8a3a7de9-1101-4199-bc3c-e66960f9cb673.gif)
![C語言程序設計教程_楊路明__課后習習題答案_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/26/8a3a7de9-1101-4199-bc3c-e66960f9cb67/8a3a7de9-1101-4199-bc3c-e66960f9cb674.gif)
![C語言程序設計教程_楊路明__課后習習題答案_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/26/8a3a7de9-1101-4199-bc3c-e66960f9cb67/8a3a7de9-1101-4199-bc3c-e66960f9cb675.gif)
版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、C語言程序設計教程 楊路明 課后習題答案 北京郵電大學出版社第一章1、算法描述主要是用兩種基本方法:第一是自然語言描述,第二是使用專用工具進行算法描述2、c語言程序的結構如下:c語言程序由函數(shù)組成,每個程序必須具有一個main函數(shù)作為程序的主控函數(shù)。"/*"與"*/"之間的內(nèi)容構成c語言程序的注釋部分。用預處理命令#include可以包含有關文件的信息。大小寫字母在c語言中是有區(qū)別的。除main函數(shù)和標準庫函數(shù)以外,用戶可以自己編寫函數(shù),程序一般由多個函數(shù)組成,這些函數(shù)制定實際所需要做的工作。例如:void main()int a,b,c,s;a=8;b
2、=12;c=6;s=a b*c;printf("s=%d",s);3、c語言的特點:c語言具有結構語言的特點,程序之間很容易實現(xiàn)段的共享;c語言的主要結構成分為函數(shù),函數(shù)可以在程序中被定義完成獨立的任務,獨立地編譯成代碼,以實現(xiàn)程序的模塊化。c語言運算符豐富,運算包含的范圍很廣;c語言數(shù)據(jù)類型豐富。c語言允許直接訪問物理地址,即可直接對硬件進行操作,實現(xiàn)匯編語言的大部分功能;c語言語法限制不太嚴格,程序設計自由度大,這樣是c語言能夠減少對程序員的束縛;用c語言編程,生成的目標代碼質(zhì)量高,程序執(zhí)行效率高,可移植性好;4、合法標識符:AB12、leed_3、EF3_3、_762
3、、PAS、XYZ43K2不合法標識符:a*b2、8stu、if、ave#xy、#_DT5、5、F2:將當前編輯器中文件存盤F10:調(diào)用主菜單F4:程序運行到光標所在行Ctrl F9:當前編輯環(huán)境下,進行編譯、連接且運行程序;Alt F5:將窗口切換到DOS下,查看程序運行結果6、(1):*welcome youvery good*(2):please input three number;5,7,8max number is:87、main8、User screen、Alt F59、標識符必須是字母或下劃線開頭,大小寫字母含義不同。由數(shù)字、字母和下劃線組成;關鍵字是一種語言中規(guī)定具有特定含義的
4、標識符。關鍵字不能作為變量或函數(shù)名來使用,用戶只能根據(jù)系統(tǒng)的規(guī)定使用它們。10、選擇主菜單File項下拉子菜單中Save項或直接按F2鍵存盤。第二章1、符合C語法規(guī)定的常數(shù)為:0x1e、"ab"、2、(1):錯誤如下:int x,y=5,z=5,aver;x=7;aver = (x y x)/3;結果如下:AVER=5(2):錯誤如下:char c1='a',c2='b',c3='c'printf("a=_end",a,b);結果如下:a=3b='A'"end"aabcc
5、 abc3、4、(1):9,11,9,10(2):3,1,0,0(3):11,19,31,15、(1):0(2):0(3):(4):90(5):10(6):10(7):65(8):4(9):(10):1(11):0(12):20(13):06、(5)7、求x的絕對值8、c>(max=a>ba:b)c:max;9、B10、D第三章1、輸入函數(shù)scanf的參數(shù)錯誤,應該為:scanf("%f",&k);2、|1234 1234 |3、ff104、1,3,15、原字符串左邊加空格再加字符串本省,字符個數(shù)總和為5個6、scanf("%d,%d,%c,%
6、c",&a1,&a2,&c1,&c2);7、printf("a b=%d",a b);printf("a-b=%d",a-b);printf("a*b=%d",a*b);printf("a/b=%d",a/b);printf("(float)a/b=%f",(float)a/b);printf("a%b=%d",a%b);8、void main()float r;float s,c;printf("please input
7、the number:");scanf("%f",&r);if(r>=0)s = *r*r;c = 2*r;printf("s = %f, c = %f",s,c);elseprintf("you input number is error!");9、void main()int n;printf("please input the number:");scanf("%d",&n);if(n>=100 && n printf("%d
8、%d%d",n_,(n/10)_,n/100);elseprintf("you input number is error!");10、void main()int i,j,k;scanf("%d,%d,%d",&i,&j,&k);(i%2 != 01:0) (j%2 != 01:0) (k%2 != 01:0) = 2printf("YES"):printf("NO");11、void main()char a;scanf("%c",&a);print
9、f("%c,%c,%c",a-1,a,a 1);printf("%d,%d,%d",a-1,a,a 1);12、void main()float a,b,c,s,Area;scanf("%f,%f,%f",&a,&b,&c);if(a b > c | a c > b | b c >a)s = (a b c)/2;Area = sqrt(s*(s-a)*(s-b)*(s-c);printf("%f",Area);elseprintf("you input the n
10、umber is error!");第四章1: 02: 203: (x20)|(x4: *a=25,b=14,c=16*5: 376: if(aelse printf("2");7、#includevoid main()char a,b,t1,t2;scanf("%c,%c",&a,&b);t1=a>ba:b;t2=aif(t1-t2)%2=0)printf("%c,%c",a 1,b 1);else printf("%c,%c",a-1,b-1);getch();8、#includ
11、evoid main()int temp1=0,temp2=0,x,y,i=1;printf("Please input (x,y): ");scanf("%d,%d",&x,&y);while(i*y)if(x=(i*y) temp1=1;break;temp2=i;i ;if(temp1)printf("%d / %d = %d",x,y,i);elseprintf("%d / %d-> shang=%d,yushu=%d",x,y,temp2,x-y*temp2);getch();9、#
12、includevoid main()float x,y,m=0,n=0;scanf("%f,%f",&x,&y);n=(x-2)*(x-2);m=(y-2)*(y-2);if(m n)printf("(%.3f,%.3f)In the yuan",x,y);elseprintf("(%.3f,%.3f)out of the yuan",x,y);getch();10、#includevoid main()int temp=0,month,year;printf("Please input (year,mont
13、h): ");scanf("%d,%d",&year,&month);if(year0=0)|(year%4=0&&year_0!=0)temp=1;if(month=2)if(temp)printf("%d year %d month have 29 ",year,month);else printf("%d year %d month have 28 ",year,month);else if(month%2=0)printf("%d year %d month have 30
14、",year,month);else printf("%d year %d month have 31 ",year,month);getch();11、switch(a/10)case 5:m=4;break;case 4:m=3;break;case 3:m=2;break;case 2:m=1;break;default:m=5;12、方法一:#includevoid main()int x,y;scanf("%d",&x);if(x-5)y=x-1;else if(x=0)y=x;else if(x>0&&
15、xy=x 1;printf("%d",y);getch();方法二:#includevoid main() int x,y;scanf("%d",&x);if(x-5) if(x=0)y=x;else if(x>0&&xelse y=x-1;printf("%d",y);else printf("Input error!");getch();方法三:#includevoid main() int x,y,i;scanf("%d",&x);if(x-5) if
16、(x=0)i=1;else if(x>0&&xelse i=3;else i=4;switch(i) case 1:y=x;printf("%d",y);break;case 2:y=x 1;printf("%d",y);break;case 3:y=x-1;printf("%d",y);break;case 4:printf("Input error!");break;getch();第五章1、void main()int n,value;int i,count=0;float averag
17、e = 0;long int sum = 0;scanf("%d",&n);for(i = 0; i scanf("%d",&value);if(value%2 = 0)sum =value;count ;average = sum / (float)count;printf("the average is %f",average);2、#include ""void main()char ch;int zm = 0, sz = 0;ch = getchar();while(ch != '*
18、')if(ch >= 'A' && ch = 'a' && ch zm ;if(ch >= '0' && ch sz ;ch = getchar();printf("zm = %d ; sz = %d",zm,sz);3、void main()long i_value;int sum = 0;int temp = 0;scanf("%ld",&i_value);if(i_value for(;)temp = i_value_;i_v
19、alue = i_value/10;sum =temp;printf("%d ",temp);if(i_value = 0)break;printf("=%d",sum);4、#include ""void main()char ch;ch = getchar();while(ch != '.')if(ch >= 'A' && ch ch = ch 32;putchar(ch);else if(ch >= 'a' && ch ch = ch -
20、 32;putchar(ch);elseputchar(ch);ch = getchar();printf("");5、void main()float sum = 200;int count = 0;for(;)sum = sum sum*;count ;if(sum > 500)break;printf("the %d years later complete!",count);6、void main()int i,temp=0,bit=0;for(i = 1 ; i if(i%3 = 0)temp = i;for(;temp != 0;)bi
21、t = temp_;if(bit = 5)printf("%d,",i);break;temp = temp/10;printf("");7、#include int main(void)int steps = 29, i = 1;while ( steps % 7 )steps = (30 * i) - 1;printf("Total steps: %d", steps);return 0;8、main()int i,j,k,n;printf("the narcissus number is:");for(n=1
22、00;ni=n/100;j=n/10-i*10;k=n_;if(i*i*i j*j*j k*k*k=n) printf("%d",n);9、main() float i,j,temp,n,sum;int t;i=2;j=1;sum=0;scanf("%d",&t);for(n=1;nsum=sum i/j;temp=i;i=i j;j=temp;printf("2/1 3/2 5/3 8/5 13/8 .=%f",sum);10、void main()int nWidth,a,b;scanf("%d",&a
23、mp;nWidth);for(a=(nWidth%2);afor(b=0;bchar chOut =' 'int nleft =(nWidth -a)/2;int nright = (nWidth a)/2;if(b>=nleft&&bchOut ='*'printf("%c",chOut);printf("");r11、void main()int i=1,j=1;for(i=1;ifor(j=1;jprintf("%d*%d=%d",i,j,i*j);printf("
24、")12、#include ""void main()char c;id,);size ;while(workersize-1.sid!=0);return worker;void paixu(struct work a) int i,j,k;long t;char v15;for(i=0;i k=i;for(j=i;jif(ai.sid>aj.sid)k=j;if(k!=i) t=ai.sid; ai.sid=aj.sid; aj.sid=t;strcpy(v,);strcpy(,);
25、strcpy(,v); for(i=0;iprintf("sid: %ld:%s",ai.sid,);getch();void select(struct work a) int i=0,found=1;long num;printf("Input select sid: ");scanf("%ld",&num);for(i=0;i if(ai.sid=num) found=0;printf("%ld: %s",num,);break;if(found)printf
26、("this sid!");getch();void main() struct work *p;p=set_list();paixu(p);select(p);10、#includefloat jiecheng(int n) long s=1;int i;for(i=1;is=s*i;return s;float chengfang(float x,int n) float s=1;int i;for(i=1;is=s*x;return s;float f(float x,int n) float s=1,t=0;int i=1,j=-1;for(i=1;i t=j*ch
27、engfang(x,2*i)/jiecheng(2*i);s =t;j=j*j;return s;main() float s1=0,s2=0,s3=0,s4=0,x=;int n=7;s1=f(x,n);s2=f(x ,n);s3=f,n 3);s4=s1/(s2 s3);printf("%f",s4);getch();第七章1: (1) D(2) A(3) D(4) B(5) D2: (1) 1 5 4 46 7 82 34(2) 63333: (1)a8=data; k>=0 ak=temp break k(2) "%s" stri4、/*題
28、目:求一組成績的平均分數(shù)以及高于平均分的成績。*/#include#define max 100void main()float amax,s=0,average=0;int i,n;printf("Please input N: "); /*輸入要處理元素的個數(shù)*/scanf("%d",&n);printf("input %d ge shu: ",n); /*輸入90,85,92,77,80,62*/ for(i=0;iscanf("%f",&ai);s =ai;average = s / n;p
29、rintf("= %.2f",average); /*輸出*/for(i=0;iif(ai>average)printf("%.2f ",ai); /*輸出 , ,*/5、/*題目:編寫程序,輸入一組整數(shù),將他們排序后由小到大輸出。*/#include#define max 100void main()int amax,j,i,k=0,t=0,n=0;printf("Please input N: "); /*輸入要處理元素的個數(shù)*/scanf("%d",&n);for(i=0;iscanf(&quo
30、t;%d",&ai);for(i=0;i k=i;for(j=i 1;jif(ak>aj)k=j;if(k!=i) /*元素排序前下標與排序后下標不符,則交換其值*/ t=ai;ai=ak;ak=t;printf("");for(i=0;iprintf("%d ",ai);6、/*題目:從鍵盤輸入一個4x4的整數(shù)矩陣,以主對角線(猿浦/*將左下角元素中較大者替換右上角元素,并將右上角含對稱軸輸出。*/#include#includevoid main()int d44=0,0,0,0,i,j;clrscr();printf(&qu
31、ot;input 16 num: ");for(i=0;ifor(j=0;jscanf("%d",&dij);for(i=0;ifor(j=0;jif(dij>dji) /*左下角元素大于右上角元素則交換*/dji=dij;for(i=0;i printf("");/*為了保持每行的間隔與每列的相同*/for(j=0;jif(j>=i)printf("%d",dij);/*為了使位數(shù)不同的數(shù)輸出依然保持三角型* / elseprintf("");7、*題目:輸入一個3x4的二維數(shù)組,然
32、后分別按行和按列輸出。*/#include#includevoid main()int d34=0,0,0,0,i,j;printf("Please input 12 num: ");for(i=0;ifor(j=0;jscanf("%d",&dij);printf("hang: ");for(i=0;ifor(j=0;jprintf("%d ",dij);printf(" lie: ");for(i=0;ifor(j=0;jprintf("%d ",dji);8、/
33、*題目:編寫程序,將兩個字符串連接起來,不用strcat函數(shù)。*/#include#includevoid main() char s150,s250;int i=0,j=0,t=0;printf("Input one: ");gets(s1);while(s1i!='') i ; /*統(tǒng)計s1中字符個數(shù)*/printf("second: ");gets(s2);while(s2j!='') j ; /*統(tǒng)計s2中字符個數(shù)*/for(t=0;t s1i=s2t; i ;printf(" second: "
34、;);puts(s1);9、/*輸入一行字符串,統(tǒng)計字符對ab的個數(shù)。*/#include#include#define MAX 100void main()char strMAX;int i=0,flage=0;int count=0;printf("input a string: ");gets(str);while(stri) if(stri='a')flage=1;else if(stri='b')if(flage=1) count ;flage=0;else flage=0;i ;printf("the double ch
35、ar ab count is %d",count);10、#include /*相對于第一種方法,這種方法能把同為最大的字符串全部打印出來。*/#includeint paixu(int a,int n) /*構造對長度為n的數(shù)組排序的函數(shù)*/int i,j,t,k,temp;for(i=0;i k=i;for(j=i 1;jif(ak>aj)k=j;if(k!=i) t=ai;ai=ak;ak=t;temp=an-1;return temp; /*返回最大字符串的長度的值*/void main()char str150,str250,str350,str450,str550,
36、str650;char str750,str850,str950,str1050;int count10=0,temp10=0,i,j;int paixu(int a,int n);for(i=1;iprintf("input %d string: ",i);if(i=1) gets(str1);while(str1count0)count0 ;temp0 ; if(i=2) gets(str2);while(str2count1)count1 ;temp1 ;if(i=3) gets(str3);while(str3count2)count2 ;temp2 ; if(i=
37、4) gets(str4);while(str4count3)count3 ; temp3 ;if(i=5) gets(str5);while(str5count4)count4 ; temp4 ;if(i=6) gets(str6);while(str6count5)count5 ; temp5 ;if(i=7) gets(str7);while(str7count6)count6 ; temp6 ;if(i=8) gets(str8);while(str8count7)count7 ; temp7 ;if(i=9) gets(str9);while(str9count8)count8 ; temp8 ;if(i=10) gets(str10);while(str10count9)count9 ;temp9 ;j=paixu(temp,10);for(i=1;iif(counti-1=j) /*只要字符串長度與最大長度相等就打印出來*/ switch(i) case 1:puts(str1); printf(""); break;case 2:puts(str2); printf(""); break;c
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年高精度燃油濾紙合作協(xié)議書
- 2025年電控多瓶采水器合作協(xié)議書
- 八年級英語下冊 Unit 10 單元綜合測試卷(人教河南版 2025年春)
- 人教版 七年級英語下冊 UNIT 7 單元綜合測試卷(2025年春)
- 育嬰師服務協(xié)議書
- 信息技術在幼兒園一日活動中的運用
- 2025年個人承包魚塘合同(2篇)
- 2025年個體經(jīng)營勞動合同(4篇)
- 2025年五年級數(shù)學上學期教師工作總結樣本(四篇)
- 2025年臨床試驗合作協(xié)議參考模板(三篇)
- 2025年個人學習領導講話心得體會和工作措施例文(6篇)
- 2025大連機場招聘109人易考易錯模擬試題(共500題)試卷后附參考答案
- 2020-2025年中國中小企業(yè)行業(yè)市場調(diào)研分析及投資戰(zhàn)略咨詢報告
- 2025-2030年中國電動高爾夫球車市場運行狀況及未來發(fā)展趨勢分析報告
- 物流中心原材料入庫流程
- 河南省濮陽市2024-2025學年高一上學期1月期末考試語文試題(含答案)
- 長沙市2025屆中考生物押題試卷含解析
- 2024年08月北京中信銀行北京分行社會招考(826)筆試歷年參考題庫附帶答案詳解
- 2024年芽苗菜市場調(diào)查報告
- 蘇教版二年級數(shù)學下冊全冊教學設計
- 職業(yè)技術學院教學質(zhì)量監(jiān)控與評估處2025年教學質(zhì)量監(jiān)控督導工作計劃
評論
0/150
提交評論