版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、C Primer Plus第六版中文版習(xí)題答案Github: zhayujie/C-Primer-Plus第一章1.#include int main(void) double inch, cm; printf(Please input the inches: ); scanf(%lf, &inch); cm = inch * ; printf(%g cmn, cm); return 0;第二章3.#includeint main(void) int days,years=21; days=years*365; printf(我的年齡是%d歲,%d天n,years,days); return
2、0;4.#includevoid jolly(void);void deny(void);int main(void) jolly(); jolly(); deny(); return 0;void jolly(void) printf(For hes a jolly good fellow!n);void deny(void) printf(Which nobody can deny!n);5.#includevoid br(void);void ic(void);int main(void) br(); printf(,); ic(); printf(n); ic(); printf(n)
3、; br(); printf(n); return 0;void br(void) printf(Brazil,Russia);void ic(void) printf(India,China);6.#includeint main(void) int toes=10; int toes_2,toes2; toes_2=2*toes; toes2=toes*toes; printf(toes是%d,toes的兩倍是%d,toes的平方是%dn,toes,toes_2,toes2); return 0;8.#includevoid one_three(void);void two(void);i
4、nt main(void) printf(starting nown); one_three();void one_three(void) printf(onen); two(); printf(threen); printf(done!n);void two(void) printf(twon);第三章2.#includeint main(void) char ch; printf(please input a number:); scanf(%d,&ch); printf(%cn,ch); return 0;4.#includeint main(void) float a; printf(
5、Enter a floating-point value: ); scanf(%f,&a); printf(fixed-point notation: %fn,a); printf(exponential notation: %en,a); return 0;5.#includeint main(void) int age; double seconds; printf(please input your age: ); scanf(%d,&age); seconds=age*; printf(the corresponding seconds are: %en,seconds); retur
6、n 0;7.#includeint main(void) float inches,cms; printf(input your height(inch): ); scanf(%f,&inches); cms=inches*; printf(your height(cm): %fn,cms); return 0;8.#includeint main(void) float pint,ounce,soupspoon,teaspoon,cup; printf(input the number of cups: ); scanf(%f,&cup); pint=cup/2; ounce=cup*8;
7、soupspoon=ounce*2; teaspoon=soupspoon*3; printf(they are equivalent of:n%f pintn%f ouncen%f soupspoonsn%f teaspoonsn,pint,ounce,soupspoon,teaspoon); return 0;第四章1.#includeint main(void) char firstname40,lastname40; printf(Input your firstname: ); scanf(%s,firstname); printf(Input your lastname: ); s
8、canf(%s,lastname); printf(Your name is %s,%sn,firstname,lastname); return 0;2.#include#includeint main(void) char name40; int width; printf(Input your name: ); scanf(%s,name); width=strlen(name)+3; printf(%*sn,width,name); #includeint main(void) float height; char name40; printf(Input your height(cm
9、) and name: ); scanf(%f%s,&height,name); height=height/100; printf(%s, you are %.3fm talln,name,height); return 0;5.#includeint main(void) float speed,size,time; printf(Input the download speed(Mb/s) and the file size(MB):n); scanf(%f%f,&speed,&size); time=size/speed*; printf(At %.2f megabits per se
10、cond, a file of %.2f megabytesn,speed,size); printf(downloads in %.2f seconds.n,time); return 0;6.#include#includeint main(void) char firstname40,lastname40; printf(Input your firstname: ); scanf(%s,firstname); printf(Input your lastname: ); scanf(%s,lastname); printf(%s %sn,firstname,lastname); pri
11、ntf(%*d %*dn, strlen(firstname),strlen(firstname),strlen(lastname),strlen(lastname); printf(%s %sn,firstname,lastname); printf(%*d %*dn, -strlen(firstname),strlen(firstname),-strlen(lastname),strlen(lastname); return 0;7.#include#includeint main(void) double a=; float b=; printf(%.6f %.6fn,a,b); 2f,
12、 %.12fn,a,b); printf(%.16f, %.16fn,a,b); printf(DBL_DIG: %dn,DBL_DIG); printf(FLT_DIG: %dn,FLT_DIG); return 0;8.#include#define GALLON fn,mile/gallon); printf(Litre per 100 kilometers: %.1fn, gallon*GALLON/(mile*MILE)*100); return 0;第五章1.#include#define H_P_M 60 n,min,hour,left); printf(Enter your n
13、ext value: ); scanf(%d,&min); printf(Good bye!n); return 0;2.#includeint main(void) int num,count; printf(Input a integer: ); scanf(%d,&num); count=0; while(count+11) printf(%d ,num); num+; printf(n); return 0;3.#include#define DAYS_PER_WEEK 7 n,day,week,left); printf(Next input: ); scanf(%d,&day);
14、return 0;4.#include#define CM_PER_FEET f cm = %d feet, %.1f inchesn,cm,feet,inch); printf(Enter a height in centimeters (=0 to quit): ); scanf(%f,&cm); printf(byen); return 0; 5.#includeint main(void) int count,sum,days; printf(Input the number of days: ); scanf(%d,&days); count=sum=0; while(count+d
15、ays) sum=sum+count; printf(The money you earned: %dn,sum); return 0;6.#includeint main(void) int count,sum,days; printf(Input the number of days: ); scanf(%d,&days); count=sum=0; while(count+days) sum=sum+count*count; printf(The money you earned: %dn,sum); return 0;7.#includevoid cube(double n);int
16、main(void) double num; printf(Input a number: ); scanf(%lf,&num); cube(num);void cube(double n) printf(The cube of %f is %fn,n,n*n*n);8.#includeint main(void) int num1,num2; printf(This program computes moduli.n); printf(Enter an integer to serve as the second operand: ); scanf(%d,&num1); printf(Now
17、 enter the first operand: ); scanf(%d,&num2); while(num20) printf(%d % %d is %dn,num2,num1,num2%num1); printf(Enter next number for first operand (= 0 to quit): ); scanf(%d,&num2); printf(Donen);9.#includevoid Temperatures(double fah);int main(void) double fah,cel,kel;n);void Temperatures(double fah
18、) const double a=,b=,c=,d=; printf(%.2f is %.2f , %.2f K.n, fah,a/b*(fah-c),a/b*(fah-c)+d);第六章1.#include#define SIZE 26int main(void) char chSIZE; int index; for(index=0;indexSIZE;index+) chindex=a+index; printf(%c ,chindex); printf(n); return 0; 2.#includeint main(void) int i,j; for(i=1;i=5;i+) for
19、(j=1;j=i;j+) printf($); printf(n); return 0;3.#includeint main(void) int i,j; for(i=1;i=6;i+) for(j=0;ji;j+) printf(%c,F-j); printf(n); return 0;4.#include#define ROWS 6int main(void) char ch; int i,j; for(ch=A,i=0;iROWS;i+) for(j=0;j=i;j+) printf(%c,ch+); printf(n); return 0;5.#include#define ROWS
20、5int main(void) char ch=A; int i,j; for(i=1;i=ROWS;i+) for(j=1;j=ROWS-i;j+) printf( ); for(j=0;j=0;j-) printf(%c,ch+j); printf(n); return 0;6.#includeint main(void) int max,min,num; printf(Input the min and max: ); scanf(%d%d,&min,&max); printf(%10s%10s%10sn,number,square,cube); for(num=min;num=max;
21、num+) printf(%10d%10d%10dn,num,num*num,num*num*num); return 0;7.#includeint main(void) double n1,n2; printf(Input two numbers: ); while(2=scanf(%lf%lf,&n1,&n2) printf(%fn,(n1-n2)/n1*n2); printf(Input your next pair of numbers: ); printf(Bye!n); return 0;9.#includedouble calculate(double n1, double n
22、2);int main(void) double num1, num2; printf(Input two numbers: ); while (2 = scanf(%lf%lf, &num1, &num2) #include int main(void) int lower, upper; int num, sum; printf(Enter lower and upper integer limits: ); scanf(%d%d, &lower, &upper); while (lower upper) for (sum=0, num=lower; num = upper; num+)
23、sum = sum + num * num; #include #define SIZE 8int main(void) int numSIZE; int index; printf(Enter 8 integers: ); for (index=0; indexSIZE; index+) #include int main(void) double sum1=0, sum2=0; int count, items, sign; printf(Enter the items: ); scanf(%d, &items); . = %fn, sum1); printf( - + - + . = %
24、fn, sum2); return 0;13.#include #define SIZE 8int main(void) int index, count, numSIZE; for (index = 0, count = 1; index SIZE; index+) count *= 2; numindex = count; #include #define SIZE 8int main() double num1SIZE, num2SIZE; int index1, index2, index; printf(Enter 8 numbers to the first array:n); f
25、or (index1 = 0; index1 SIZE; index1+) scanf(%lf, &num1index1);#include #include #define SIZE 255int main(void) int index; char chSIZE; printf(Enter a line: ); for(index = 0, scanf(%c, &ch0); chindex != n;) index+; scanf(%c, &chindex); #include #define RATE_DAPHNE #define RATE_DEIRDRE n, year, daphne
26、, deirdre);#include #define INITIAL_MONEY 100n, year); return 0;18.#include #defineINITIAL_NUMBER 5 #include int main(void) char ch; int n_space = 0;n); while (ch = getchar() != #) if (ch = ) n_space+; else if (ch = n) n_newline+; else n_others+; printf(Spaces: %d, newlines: %d, others: %dn, n_space
27、, n_newline, n_others); return 0;2.#include #define CHARS_PER_LINE 8#include int main(void) int num; int n_even = 0, n_odd = 0;fn, n_even, (n_even = 0) 0 : (float)sum_even / n_even); printf(The number of odd numbers is %d, and the everrage of odd numers is %.2fn, n_odd, (n_odd = 0) 0 : (float)sum_od
28、d / n_odd); return 0;4.#include int main(void) char ch; int n_repl = 0; ch = !; n_repl+; n, n_repl); return 0;5.#include int main(void) char ch; int n_repl = 0;: ch = !; n_repl+; break; case !: printf(!); n_repl+; break; default: break; n, n_repl); return 0;6.#include int main(void) char ch; char la
29、st_ch = 0; n, count); return 0;7.#include #define BASE 1000lfnYour tax is $%.2lfn Your net income is $%.2lfn, gross, tax, (gross - tax); return 0;8.#include #define BASE1 #define BASE2 #define BASE3 #define BASE4 n); return 0; default: printf(Please input the right option.n); goto printpart; lfnYour
30、 tax is $%.2lfn Your net income is $%.2lfn, gross, tax, (gross - tax); printf(nYour next choice:n); return 0;9.#include int main(void) int div, prime; int num, count; int flag; printf(Input a positive integer: ); scanf(%d, &num); printf(The prime numbers in range:n); for (prime = 2; prime = num; pri
31、me+)#include #define RATE1 #define RATE2 #define SINGLE 17850n); scanf(%d, &num); switch (num) case 1: tax_break = SINGLE; break; case 2: tax_break = HOST; break; case 3: tax_break = MAR_SHA; break; case 4: tax_break = MAR_DEV; break; case 5:printf(quit.n); return 0; default: printf(Please input rig
32、ht number.); goto printpart;lf.n, tax); printf(Your next input: n); goto printpart;#include #include #define ARTICHOKE f/lbn, ARTICHOKE); printf(b: beet $%.2f/lbn, BEET); printf(c: carrot $%.2f/lbn, CARROT); printf(q: quit.n); ; while (getchar () != n) continue;n); return 0; f/lb weight: %.2f pounds
33、 cost: $%.2fn, ARTICHOKE, weight_artichoke, weight_artichoke * ARTICHOKE); if (weight_beet) printf(beet Price: $%.2f/lb weight: %.2f pounds cost: $%.2fn, BEET, weight_beet, weight_beet * BEET); if (weight_carrot) printf(carrot Price: $%.2f/lb weight: %.2f pounds cost: $%.2fn, CARROT, weight_carrot,
34、weight_carrot * CARROT); printf(The order cost: $%.2fn, veg_cost); if (discount) printf (You have %.f discount, and the reduced money is $%.2fn, DISCOUNT_RATE * 100, discount); printf(The packing and transpoting fee is $%.2fn, pack_tran_fee); printf(The total cost is $%.2fn, total_cost); #include in
35、t main(void) int ch; int count = 0; while (ch = getchar() != EOF) count+; printf(The number of characters is %dn, count); return 0;2.#include #define SPACE 32#define CTRL 64#define COL 10#include #include int main(void) int lower = 0, upper = 0; char ch; printf(Input some texts:n); while (ch = getch
36、ar() != EOF) if (islower(ch) lower+; if (isupper(ch) upper+; printf(lower:%d, upper:%dn, lower, upper); return 0;4.#include #include int main(void) char ch; int inword = 0;f.n, (double)chars / (double)words); return 0; 5.#include #define LOW 1I will try to guess , LOW, HIGH); printf(it.nRespond with
37、 a y if my guess is right, with an s if itn); printf(is small and with a b if it is big.n); printf(Uh.is your number %dn, guess); while (response = getchar() != y) if (response = s) low = guess; guess = (guess + high) / 2; else if (response = b) high = guess; guess = (guess + low) / 2; else printf(S
38、orry, I understand only y, s and b.n); printf(Well, then, is it %dn, guess); #include #include char get_first(void);int main(void) char ch; while (ch = get_first() != EOF) putchar(ch); printf(n); return 0;char get_first(void) char ch; while (isspace(ch = getchar() continue; while (getchar() != n) co
39、ntinue; return ch;7.#include #define BASE1 #define BASE2 #define BASE3 #define BASE4 n); break; if (choice = a & choice = d) calculate(base); return 0; lfnYour tax is $%.2lfn Your net income is $%.2lfn, gross, tax, (gross - tax); printf(n);#include float get_float(void);char get_choice(void);char ge
40、t_first(void);int main(void) char choice; float num1, num2; while (choice = get_choice() != q) printf(Enter first number: ); num1 = get_float(); printf(Enter second number: ); num2 = get_float(); switch (choice) case a: printf(%.2f + %.2f = %.2fn, num1, num2, num1 + num2); break; case s: printf(.2%f - %.2f = %.2fn, num1, num2, num1 - num2); break; case m: printf(%.2f * %.2f = %.2fn, num1, num2, num1 * num2); break; case d: if (!num2) printf(Enter a number other than 0: ); num2 = get_float(); prin
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中國(guó)毛染行業(yè)市場(chǎng)發(fā)展前景及發(fā)展趨勢(shì)與投資戰(zhàn)略研究報(bào)告
- 個(gè)人珠寶購(gòu)買(mǎi)合同范本
- 農(nóng)戶(hù)小麥預(yù)定合同范本
- 出國(guó)境旅游合同范本
- 北京市設(shè)備采購(gòu)合同范本
- 中英文商品合同范本
- 2024年安全準(zhǔn)入考試(外協(xié)搶修、施工人員)練習(xí)試題及答案
- 人力資源外包合同范本
- 2025年度高端倉(cāng)儲(chǔ)庫(kù)房承包合同示范范本
- 農(nóng)村 住房 出租合同范例
- 二零二五年度大型自動(dòng)化設(shè)備買(mǎi)賣(mài)合同模板2篇
- 2024版金礦居間合同協(xié)議書(shū)
- GA/T 2145-2024法庭科學(xué)涉火案件物證檢驗(yàn)實(shí)驗(yàn)室建設(shè)技術(shù)規(guī)范
- 2025內(nèi)蒙古匯能煤化工限公司招聘300人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025年中國(guó)融通資產(chǎn)管理集團(tuán)限公司春季招聘(511人)高頻重點(diǎn)提升(共500題)附帶答案詳解
- 寵物護(hù)理行業(yè)客戶(hù)回訪(fǎng)制度構(gòu)建
- 電廠(chǎng)檢修管理
- 《SPIN銷(xiāo)售法課件》課件
- 機(jī)動(dòng)車(chē)屬性鑒定申請(qǐng)書(shū)
- 2024年中考語(yǔ)文試題分類(lèi)匯編:非連續(xù)性文本閱讀(學(xué)生版)
- 門(mén)店禮儀培訓(xùn)
評(píng)論
0/150
提交評(píng)論