c程序设计(第三版)答案 作者:谭浩强
新世纪计算机基础教育丛书 清华大学出版社 第一章 1.6 main()
{int a,b,c,max;
printf(\ scanf(\ max=a;
if(max
printf(\}
第二章
2.3
(1)(10)10=(12)8=(a)16 (2)(32)10=(40)8=(20)16 (3)(75)10=(113)8=(4b)16 (4)(-617)10=(176627)8=(fd97)16 (5)(-111)10=(177621)8=(ff91)16 (6)(2483)10=(4663)8=(963)16
(7)(-28654)10=(110022)8=(9012)16 (8)(21003)10=(51013)8=(520b)16 2.6
aabb (8)cc (8)abc (7)AN 2.7 main()
{char c1='C',c2='h',c3='i',c4='n',c5='a'; c1+=4, c2+=4, c3+=4, c4+=4, c5+=4; printf(\} 2.8 main() {int c1,c2; c1=97;c2=98;
printf(\ %c\}
1
2.9 (1)=2.5 (2)=3.5 2.10 9,11,9,10
2.12
(1)24 (2)10 (3)60 (4)0 (5)0 (6)0
第三章 3.4 main() {int a,b,c; long int u,n; float x,y,z; char c1,c2; a=3;b=4;c=5;
x=1.2;y=2.4;z=-3.6; u=51274;n=128765; c1='a';c2='b';
printf(\
printf(\ b=- c=-\\n\printf(\,z);
printf(\ y+z=%5.2f z+x=%5.2f\\n\,y+z,z+x);
printf(\ n=%9ld\\n\
printf(\ printf(\} 3.5 57
5 7
67.856400,-789.123962
67.856400,-789.123962
67.86 -789.12,67.856400,-789.123962,67.856400,-789.123962 6.785640e+001,-7.89e+002 A,65,101,41
1234567,4553207,d687 65535,177777,ffff,-1 COMPUTER, COM 3.6
a=3 b=7/
2
x=8.5 y=71.82/
c1=A c2=a/ 3.7
10 20Aa1.5 -3.75 +1.4,67.8/
(空3)10(空3)20Aa1.5(空1)-3.75(空1)(随意输入一个数),67.8回车 3.8 main()
{float pi,h,r,l,s,sq,sv,sz; pi=3.1415926;
printf(\ scanf(\ l=2*pi*r; s=r*r*pi; sq=4*pi*r*r; sv=4.0/3.0*pi*r*r*r; sz=pi*r*r*h;
printf(\ printf(\ printf(\ printf(\ printf(\} 3.9 main()
{float c,f;
scanf(\ c=(5.0/9.0)*(f-32); printf(\}
3.10
#i nclude\main() {char c1,c2;
scanf(\ putchar(c1); putchar(c2); printf(\
printf(\}
3
第四章
4.3
(1)0 (2)1 (3)1 (4)0 (5)1 4.4 main() {int a,b,c;
scanf(\ if(a
printf(\ else
printf(\ else if(a printf(\ else printf(\} main() {int a,b,c,temp,max; scanf(\ temp=(a>b)?a:b; max=(c>temp)?c:temp; printf(\} 4.5 main() {int x,y; scanf(\ if(x<1)y=x; else if(x<10)y=2*x-1; else y=3*x-11; printf(\} 4.6 main() {int score,temp,logic; char grade; logic=1; while(logic) {scanf(\ if(score>=0&&score<=100)logic=0; 4 } if(score==100) temp=9; else temp=(score-score)/10; switch(temp) {case 9:grade='A';break; case 8:grade='B';break; case 7:grade='C';break; case 6:grade='D';break; case 5: case 4: case 3: case 2: case 1: case 0:grade='E'; } printf\} 4.7 main() {long int num; int indiv,ten,hundred,thousand,ten_thousand,place; scanf(\ if(num>9999) place=5; else if(num>999) place=4; else if(num>99) place=3; else if(num>9) place=2; else place=1; printf(\ ten_thousand=num/10000; thousand=(num-ten_thousand*10000)/1000; hundred=(num-ten_thousand*10000-thousand*1000)/100; ten=(num-ten_thousand*10000-thousand*1000-hundred*100)/10; indiv=num-ten_thousand*10000-thousand*1000-hundred*100-ten*10; switch(place) {case 5:printf(\ printf(\ break; case 4:printf(\ printf(\ break; case 3:printf(\ 5