![c程序設(shè)計(jì)課后習(xí)題答案(楊長(zhǎng)興__劉衛(wèi)國(guó)主編)1111_第1頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-2/13/a4067f38-b5c8-40f6-b8e5-ae5c4a9c9106/a4067f38-b5c8-40f6-b8e5-ae5c4a9c91061.gif)
![c程序設(shè)計(jì)課后習(xí)題答案(楊長(zhǎng)興__劉衛(wèi)國(guó)主編)1111_第2頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-2/13/a4067f38-b5c8-40f6-b8e5-ae5c4a9c9106/a4067f38-b5c8-40f6-b8e5-ae5c4a9c91062.gif)
![c程序設(shè)計(jì)課后習(xí)題答案(楊長(zhǎng)興__劉衛(wèi)國(guó)主編)1111_第3頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-2/13/a4067f38-b5c8-40f6-b8e5-ae5c4a9c9106/a4067f38-b5c8-40f6-b8e5-ae5c4a9c91063.gif)
![c程序設(shè)計(jì)課后習(xí)題答案(楊長(zhǎng)興__劉衛(wèi)國(guó)主編)1111_第4頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-2/13/a4067f38-b5c8-40f6-b8e5-ae5c4a9c9106/a4067f38-b5c8-40f6-b8e5-ae5c4a9c91064.gif)
![c程序設(shè)計(jì)課后習(xí)題答案(楊長(zhǎng)興__劉衛(wèi)國(guó)主編)1111_第5頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-2/13/a4067f38-b5c8-40f6-b8e5-ae5c4a9c9106/a4067f38-b5c8-40f6-b8e5-ae5c4a9c91065.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、 習(xí)題一一、 選擇題1.C2. C3.B4.C 5.C6.D7.C8.A9.B10.D二、 填空題1. 算法2. main3. ;4. cpp obj exe5. 符號(hào) 定義6. 是10 是11 7. double 18. -2649. 是410. m-m/n*n11. a為6 b為4 c為212. 為1三、 問(wèn)答題1 有點(diǎn)。計(jì)算機(jī)程序設(shè)計(jì)語(yǔ)言模型是更規(guī)則、無(wú)二意性的語(yǔ)言模型。2 書(shū)P33 .dsw 、.dsp、.ncp、.cpp4 提高程序的可讀性、可維護(hù)性。在行注釋前加“/”。段注釋放入“/*”和“*/”之間。注釋對(duì)原程序的編譯和運(yùn)行沒(méi)影響。5 設(shè)置符號(hào)常量主要提高源程序的可讀性、維護(hù)性。
2、區(qū)別:1.識(shí)別時(shí),主要看符號(hào)的定義;2.運(yùn)行時(shí),符號(hào)常量不能改變值而變量可改變。6 字符常量通常指一個(gè)字符,存儲(chǔ)單元為一個(gè)字節(jié);字符串可包含多個(gè)字符,存儲(chǔ)單元為字符數(shù)加1個(gè)字節(jié)。7 1.0 、1.1e2 類(lèi)型:double; 1L、65536 類(lèi)型:long8 int、new 不是,因?yàn)槭顷P(guān)鍵字;abc、lxyz、a_0、Hello、aaaaa、_a是合法的標(biāo)識(shí)符;a+b、!A不是,因?yàn)?、!是運(yùn)算符。0_abc不是是因?yàn)閿?shù)字開(kāi)頭;d$a不是是因?yàn)闃?biāo)識(shí)符不應(yīng)包含$。9 合法:(1)、(5)、(6)10 全部都是。11 a=2;b=112 2;-2;6、4、40、-3、313 (1) 4 a=3
3、 b=4 c=5; (2)5 a=3 b=4 c=6; (3)-9 a=3 b=5 c=5;(4) 4 a=4 b=4 c=414 (1) (float) k (2)x-int(x) (3)m/10%10 (4)(ch=A & ch=Z)?(ch=a+ch-A):ch習(xí)題二四、 選擇題1.B2. C3.A4.B 5.B五、 填空題1. if2. do while和for3.循環(huán)體 循環(huán)體4. 1 n+1 n5. 5,4,6三、程序閱讀題15 m=516 1 4,2 2 6,3,3 5,5 6,c=37六、 程序設(shè)計(jì)題1#include #include using namespace std;
4、 float a,b,c,s,area; void main() coutabc; if (a+bc)&(a+cb)&(b+ca) s=(a+b+c)/2;cout面積=sqrt(s*(s-a)*(s-b)*(s-c); else cout輸入的不是三角形的三條邊; 2.見(jiàn)實(shí)驗(yàn)教程p27 4.3.#include void main() float x,y; coutx; switch (int(x/1000) case 0:y=x;break;case 1:y=x*0.95;break; case 2:y=x*0.9;break; case 3:y=x*0.85;break; default
5、:y=x*0.8;cout優(yōu)惠款為:yendl; 4.見(jiàn)實(shí)驗(yàn)教程p28 5.5. #include using namespace std; int i,n; long js=1; void main() coutn; for (i=1;i=n;i+) js*=i; coutn!=js; 6. #include #include using namespace std; int n=1; float pi=0,xn=4; void main() while (fabs(xn)1.0e-8) pi+=xn;n+;xn=-4.0*sign(xn)/(2*n-1); cout=pi; 7. #inc
6、lude void main() int i,j,sum; for(i=2;i=1000;i+) sum=0; For (j=1;ji;j+)if (i%j=0) sum+=j; if (sum=i) couti; For (j=1;ji;j+) If (i%j=0) coutj,; Coutendl; 8. #include void main() int x,y,z; For (x=1;x10;x+) For (y=1;y12;y+) z=20-x-y; If (5*x+4*y+2*z=50) Cout公猴:x母猴:y小猴:z; 9. 見(jiàn)教程p60 例2.2310. 見(jiàn)實(shí)驗(yàn)教程p32 5.
7、習(xí)題三七、 選擇題1.B2.B3.C4.D 5.D八、 填空題1. 函數(shù)頭 省略能省略 應(yīng)加“;”函數(shù)頭 不加“;”2. inline flat f(int,char)3.函數(shù)體外 外部 內(nèi)部(靜態(tài)) static 文件 位置 extern4.生存期 作用域 作用域 生存期作用域 本文件5.-22 100 -3三、程序閱讀題17 S=4018 y=12919 max=820 S=29a) 程序設(shè)計(jì)題1. #include float add(int x,int y) return (float)(x+y);float fac(int n) int i; float s=1; For (i=1;
8、i=n;i+) s*=i; void main() int m,ncoutmn; coutm!+n!=add(fac(m),fac(n)endl; 2. #include #include int isprime(int n) int i; float k; k=sqrt(n); for (i=2;ik;i+) if (n%i=0) return 0; return 1;void main() int s=0,i;for (i=2;i=100;i+) if (isprime(i) s+=i;cout和:sendl; 3. 非遞歸: float pow(float a,int n) int i;
9、 float s=1; for (i=1;i=n;i+) s*=a; return s;遞歸: float pow(float a,int n) float s; if (n=0)return 1; elses=pow(a,n-1)*a; return s;4.非遞歸: float sum(int n) float s; int i; for (i=1;i=n;i+) s+=i; return s;遞歸: float sum(int n) float s; if (n=1)retrun 1; else s=sum(n-1)+n; return s;5. #include inline int
10、ischar(char n) if (n=127) return 1; return 0;void main() char a; couta;if (ischar(a) coutaendl; else cout輸入的不是英文字符:6.file1.cppfloat fac(int n) int i; float s=1; For (i=1;i=n;i+) s*=i;File2.cpp#include float pow(float a,int n) int i; float s=1; for (i=1;i=n;i+) s*=a; return s;void main() int a,b,n; c
11、outabn; coutfac(a)/pow(b,n);習(xí)題四程序設(shè)計(jì)題:1. #include void main() int a10,i,j,k,tem; for (i=0;i10;i+) cout輸入第i+1ai; for (i=0;i=8;i+) k=i; for (j=i+1;j=9;j+)if (akaj) k=j; tem=ai;ai=ak;ak=tem; coutait; 2. 設(shè):數(shù)組的大小為n,插入函數(shù)如下:int insert(int a,int n) int b,i=0,k; Coutb; while (bai & i=n) i+; if (ii;k-) ak=ak-1
12、;ai=b;return 1; else cout該數(shù)不能插入; return 0; 3.#include int a100,i,k,b; void main() i=1; while (i=100) cout輸入第ib;for (k=0;ki-1;k+) if (ak=b) break; if (k=i-1) ai+-1=b;4. #include #define lnum 10#define cnum 10void main() float alnumcnum,max,min; int i,j,k,l,fb=1; /輸入數(shù)給數(shù)組 for (i=0;ilnum;i+) for(j=0;jcn
13、um;j+)cout輸入i行jaij;/找鞍點(diǎn),先找出一行中的最大點(diǎn),然后在同列中確定是否為最小點(diǎn) for (i=0;ilnum;i+) l=0;for(k=1;kcnum;k+) if (ailaik) l=k;for(k=0;kalk) break;if (k=cnum) couti行l(wèi)列元素為鞍點(diǎn):; fb=0; elseif (fb) cout該數(shù)組無(wú)鞍點(diǎn);5. void f(int a,int n) int i,tem;for (i=0;in/2;i+) tem=ai;ai=an-1-i;an-1-i=tem;6.int f(char *s) int n=1; char *p,*p1
14、; n=strlen(s); p=s; p1=s+n-1; while (pp1) if (*p!=*p1) return 0; else p+;p1- return 1;7. #include #include void main() char str1100,str250,*p=str2;int n; Cout輸入字符串;Cin.get(str1,100);n=strlen(str1); for (i=0;in;i=i+2) *(str2+i/2)=str1i; *(Str2+i/2)=null; coutstr1:str1endl; coutstr2:str2endl; 8. #incl
15、ude using namespace stdvoid main() int i,supercn=0,lowcn=0,spacecn=0,numbercn=0,othercn=0; char a100; cout=A & ai=a & ai=0 & ai=9) numbercn+;else othercn+; cout”大寫(xiě)字母數(shù):”supercnendl; cout”小寫(xiě)字母數(shù):”lowcnendl; cout”空格數(shù):”spacecnendl; cout”數(shù)字字母數(shù):”numbercnendl; cout”其它字母數(shù):”supercnendl;9.#include using namesp
16、ace stdvoid main() int i,lable=0,count=0; char a100; cout”輸入字串:”; cin.get(a,100); while (ai) if (ai= & lable) count+;label=0;else if(ai!= ) lable=1;i+; cout”單字個(gè)數(shù):”countendl;10. #include #include using namespace std;void main() int i,maxn=0,maxxb,m=0; char a40100; cout輸入各行:endl; for (i=0;imaxn) maxxb
17、=i;maxn=m; coutamaxxbendl;11.#include #include using namespace std;void main() int i,n,m,j,k; char a40100,b100; cout輸入各國(guó)家名(一個(gè)國(guó)家一行):endl; for (i=0;i40;i+) cin.getline(ai,100); m=strlen(ai); if (m=0) break else n+; for (i=0;in-2;i+) k=i; for (j=i+1;j0) k=j; if (k!=i) strcpy(b,ai);strcpy(ai,ak);strcpy(
18、ak,b);) for (i=0;in;i+) coutaiendl;12. int find(char *s,char *word) char *p1,*p2,lable=1,firstspace=1; p1=s; p2=word; while (*p1) if (*p1= ) firstspace=1; else if(firstspace=1) lable=1; while (*p1!= & *p1 & *p2) if (*p1!=*p2) lable=0; p1+;p2+; if (lable & !*p2 & (*p1= | !*p1) return 1; if (!*p1) ret
19、urn 0; if (*p1= ) firstspace=1; else firstspace=0; p2=word; p1+; return 0;習(xí)題五九、 選擇題1.A2.D3.C4.A 5.D十、 填空題1. struct2.typedef3.1024.new delete十一、 程序閱讀題0x14 000000a cchd程序1:65 Au65a0x61000000a cchdu0x41000000a cchdu0x410000000x61a cchdu程序2:10,20,7,9四、程序設(shè)計(jì)題1.#include using namespace std;struct date int
20、year; int month;struct student long num; char name9; char sex; date birth; float totalscore; char hometown20;Void main() student s5,s1;char i,j,m5;for (i=0;i5;i+) cout”輸入第”int(i+1)si.num; cout”姓名:”; cin.get(,9); cin.readsome(m,5); coutsi.sex; cin.readsome(m,5); coutsi.birth.yearsi.birth.month; coutsi.totalscore; cout”輸入籍貫:”; cin.get(si.hometown,20); cin.readsome(m,5);for(i=0;i4;i+) for(j=i+1;j5;j+) if (si.totalscoresj.totalscore
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 酒店改造補(bǔ)貼合同協(xié)議書(shū)
- 2025年度科技園區(qū)辦公室租賃合同(科技企業(yè)版)
- 住宅精裝修合同書(shū)
- 循環(huán)經(jīng)濟(jì)與廢物資源化管理作業(yè)指導(dǎo)書(shū)
- 三農(nóng)村基層智慧城市建設(shè)與發(fā)展方案
- 網(wǎng)絡(luò)安全與數(shù)據(jù)保護(hù)技術(shù)作業(yè)指導(dǎo)書(shū)
- 房地產(chǎn)行業(yè)銷(xiāo)售與租賃管理系統(tǒng)方案
- 國(guó)際能源領(lǐng)域科技創(chuàng)新及投資協(xié)議
- 出租車(chē)承包合同協(xié)議書(shū)年
- 軟件能力評(píng)價(jià)與提升作業(yè)指導(dǎo)書(shū)
- GB/T 6403.4-2008零件倒圓與倒角
- 電力公司主要應(yīng)急物資清單
- 2023年初中道法九年級(jí)上冊(cè)知識(shí)點(diǎn)匯總(思維導(dǎo)圖)
- 《籃球主修》考核方式
- Unit 3 Times change單元教學(xué)設(shè)計(jì)
- 科室醫(yī)院感染風(fēng)險(xiǎn)評(píng)估表
- 山東省食用油(植物油)生產(chǎn)企業(yè)名錄496家
- 《智慧農(nóng)業(yè)》的ppt完整版
- GB∕T 33047.1-2016 塑料 聚合物熱重法(TG) 第1部分:通則
- 經(jīng)濟(jì)學(xué)市場(chǎng)失靈與政府失靈課件
- 電力業(yè)務(wù)許可證豁免證明
評(píng)論
0/150
提交評(píng)論