1、C语言程序设计第三版谭浩强课后习题答案完整版(完整版)(文档可以直接使用,也可根据实际需要修改使用,可编辑 欢迎下载) .5C * Very Good! * mian() printf(*); printf(n); printf(Very Good!n); printf(n); printf(*); .6 abc mian() int a,b,c,max; printf(a,b,c:n); scanf(%d,%d,%d,&a,&b,&c); max=a; if(maxb) max=b; if(maxc) max=c; printf(%d,max); 3.6 main() char c=a,c=
2、b,c3=c,c4=0,c5=6; printf(a%cb%ctc%ctabcn,c,c,c3); printf(tb%c %c,c4,c5); aabbccabc AN 3.7China4A4EEAChinaGlmreclcc3c4c5Chinaccc3c4c5Glmre #include main() char c=C,c=h,c3=i,c4=n,c5=a; c+=4; c+=4; c3+=4; c4+=4; c5+=4; printf(%c%c%c%c%cn,c,c,c3,c4,c5); Glmre 3.9 x+a%3*(int)(x+y)%/4 x=.5,a=7,y=4.7 (floa
3、t)(a+b)/+(int)x%(int)y a=,b=3,x=3.5,y=.5 .5 3.5 3.0 main() int i,j,m,n; i=8; j=0; m=+i; n=j+; printf(%d,%d,%d,%d,i,j,m,n); 990 3. aa=an a+=a a-= 3 a*=+3 4a/=a+a 5 a%=(n%=)n5 6a+=a-=a*=a () 4 () 0 (3) 60 (4) 0 (5) 0 (6) 0 44a=3b=4c=5x=.y=.4z=-3.6u=574n=8765c=ac=b a=_3_ _b=_4_ _c=_5 x=.00000,y=.400000
4、,z=-3.600000 x+y=_3.600_ _y+z=-.0_ _z+x=-.40 c=a_or_97(ASCII) c=b_or_98(ASCII) main() int a=3,b=4,c=5; long int u=574,n=8765; float x=.,y=.4,z=3.6; char c=a,c=b; printf(a=%d b=%d c=%dn,a,b,c); printf(x=%f,y=%f,z=%fn,x,y,z); printf(x+y=%5.f y+z=%5.f z+x=%5.fn,x+y,y+z,z+x); printf(u=%6ld n=%9ldn,u,n);
5、 printf(%s %s %d%sn,c=a,or,c,(ASCII); printf(%s %s %d%sn,c=a,or,c,(ASCII); 47scanfa=3b=7x=8.5y=7.8c=Ac=a main() int abfloat xychar cc scanfa=%d_b=%d&a&b scanf_x=%f_y=%e,&x&y scanf_c=%c_c=%c&c&c a=3_b=7 _x=8.5_y=7.8 _c=A_c=a 48r=.5h=3scanf main() float r,h,C,Sa,Sb,Va,Vb; scanf(%f,%f,&r,&h); C=*3.4*r;
6、 Sa=3.4*r*r; Sb=4*Sa; Va=4*3.4*r*r*r/3; Vb=Sa*h; printf(C=%.fn,C); printf(Sa=%.fnSb=%.fnVa=%.fnVb=%.fn,Sa,Sb,Va,Vb); 49 c=5(F-3)/9 main() float F,c; scanf(%f,&F); c=5*(F-3)/9; printf(c=%.f,c); 40getcharccccccASCIIputcharprintf charcc intcc #includestdio.h main() char c,c; c=getchar();c=getchar(); pu
7、tchar(c);putchar(n);putchar(c);putchar(n); #includestdio.h main() char c,c; c=getchar();c=getchar(); printf(c=%d c=%dn,c,c); printf(c=%c c=%cn,c,c); 5. 5. C 0003&53&5 5.3 a=3b=4c=5 () a+bc&b=c () a|b+c&b-c (3) !(ab)&!c| (4) !(x=a)&(y=b)&0 (5) !(a+b)+c-&b+c/ () 0 () (3) (4) 0 (5) 5.4 3abc #include ma
8、in() int a,b,c; printf(3); scanf(%d,%d,%d,&a,&b,&c); if(ab) if(bc) printf(max=%dn,c); else printf(max=%dn,b); else if(ac) printf(max=%dn,c); else printf(max=%dn,a); #include main() int a,b,c,temp,max; printf(3); scanf(%d,%d,%d,&a,&b,&c); temp=(ab)?a:b; /* abtemp */ max=(tempc)?temp:c; /* abc*/ print
9、f(3%dn,max); 5.5 xy #include main() int x,y; printf(x); scanf(%d,&x); if(x) /* x */ y=x; printf(x=%3d, y=x=%dn,x,y); else if (x0)/* x-0 */ y=*x-; printf(x=%3d, y=*x-=%dn,x,y); else /* x0 */ y=3*x-; printf(x=%3d, y=3*x-=%dn,x,y); 5.6 ABCDE90A8090B7079C60D #include main() float score; char grade; prin
10、tf(); scanf(%f,&score); while(score00|(score0) printf(n,); scanf(%f,&score); switch(int)(score/0) case 0: 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 : case : case 0: grade=E; printf(%5.f%cn,score,grade); 000(int)(score/0)
11、(score/0) 5.7 5 33 #include main() long int num; int indiv,ten,hundred,thousand,ten_thousand,place; /*/ printf(099999); scanf(%ld,&num); if (num9999) place=5; else if(num999) place=4; else if(num99) place=3; else if(num9) place=; else place=; printf(place =%dn, place); ten_thousand=num/0000; thousan
12、d=num/000%0; hundred=num/00%0; ten=num%00/0; indiv=num%0; switch(place) case 5: printf(%d,%d,%d,%d,%d,ten_thousand,thousand,hundred,ten,indiv); printf(n); printf(%d%d%d%d%dn,indiv,ten,hundred,thousand,ten_thousand); break; case 4: printf(%d,%d,%d,%d,thousand,hundred,ten,indiv); printf(n); printf(%d%
13、d%d%dn,indiv,ten,hundred,thousand); break; case 3: printf(%d,%d,%d,hundred,ten,indiv); printf(n); printf(%d%d%dn,indiv,ten,hundred); break; case : printf(%d,%d,ten,indiv); printf(n); printf(%d%dn,indiv,ten); break; case : printf(%d,indiv); printf(n); printf(%dn,indiv); break; 5.8 I00% 0000000I000000
14、0%07.5% 00000I400000005%40000000000000%I()if()switch 500%57.5% () if #include main() long i; float bonus,bon,bon,bon4,bon6,bon0; bon=00000*0.; /*0*/ bon=bon+00000*0.075; /*0*/ bon4=bon+00000*0.05; /*40*/ bon6=bon4+00000*0.03; /*60*/ bon0=bon6+400000*0.05; /*00*/ printf(i); scanf(%ld,&i); if(i=00000)
15、 bonus=i*0.; /*00.*/ else if(i=00000) bonus=bon+(i-00000)*0.075; /*00*/ else if(i=400000) bonus=bon+(i-00000)*0.05; /*040*/ else if(i=600000) bonus=bon4+(i-400000)*0.03; /*4060*/ else if(i=000000) bonus=bon6+(i-600000)*0.05; /*6000*/ else bonus=bon0+(i-000000)*0.0; /*00*/ printf(%0.fn,bonus); 000000
16、000.0(num-00000)0.0750400000000.00.0750(num-00000)0.0500406000bonbonbon4bon6hon0 () switch ibranch branch 0 =i*0. =bon+(i-05)*0.075 =bon+(i-*05)*0.05 3 4 =bon4+(i-4*05)*0.03 5 6 =bon6+(i-6*05)*0.05 7 8 9 0 =bon0+(i-06)*0.0 #include main() long i; float bonus, bon, bon, bon4, bon6, bon0; int c; bon=0
17、0000*0.; bon=bon+00000*0.075; bon4=bon+00000*0.05; bon6=bon4+00000*0.03; bon0=bon6+400000*0.05; printf(i); scanf(%ld,&i); c=i/00000; if(c0) c=0; switch(c) case 0: bonus=*0.;break; case : bonus=bon+(i-00000)*0.075;break; case : case 3: bonus=bon+(i-00000)*0.05; break; case 4: case 5: bonus=bon4+(i-40
18、0000)*0.03;break; case 6: case 7: case 8: case 9: bonus=bon6+(i-600000)*0.05;break; case 0: bonus=bon0+(i-000000)*0.0; printf(%0.f,bonus); 5.9 4 #include main() int t,a,b,c,d; printf(4); scanf(%d,%d,%d,%d,&a,&b,&c,&d); printf(n a=%d,b=%d,c=%d,d=%dn,a,b,c,d); if(ab) t=a; a=b; b=t; if(ac) t=a; a=c; c=
19、t; if(ad) t=a; a=d; d=t; if(bc) t=a; b=c; c=t; if(bd) t=b; b=d; d=t; if(cd) t=c; c=d; d=t; printf(n); printf(%d, %d, %d, %dn,a,b,c,d); 5.0 4()(-)(-)(-)40m() #include main() int h=0; float x=,y=,x=-,y=,x3=-,y3=-,x4=-,y4=-,x,y,d,d,d3,d4; printf(x,y); scanf(%f,%f,&x,&y); d=(x-x)*(x-x)+(y-y)*(y-y); /*/
20、d=(x-x)*(x-x)+(y+y)*(y+y); d3=(x+x3)*(x+x3)+(y-y3)*(y-y3); d4=(x+x4)*(x-x4)*(y+y4)*(y+y4); if(d&d&d3&d4) h=0; /*/ printf(%dn,h); 6.mn main() long m,n,i=,j,s; scanf(%ld,%ld,&m,&n); for(;i=m&i=n) j=m; else j=n; for(;!(j%m=0&j%n=0);j+); printf(s=%ld,j=%ldn,s,j); 6. #includestdio.h main() char c;int i=0
21、,j=0,k=0,l=0; while(c=getchar()!=n) if(c=65&c=97&c=48&c=57) j+; else if(c=3) k+; else l+; printf(i=%d,j=%d,k=%d,l=%dn,i,j,k,l); 6.3Sn=a+aa+aaa+.+aa.aaanaa+n=5n #includemath.h main() int n,sum=0,i=,s=; scanf(%d,&n); while(i=n) sum=sum+s;s=s+*pow(0,i); i+; printf(sum=%dn,sum); 6.4 !+!+3!+4!+5!+.+0! ma
22、in() int n,i=;long sum=0,s=; scanf(%d,&n); while(i=n) s=s*i;sum=sum+s;i+; printf(sum=%ldn,sum); 6.5 main() double i=,j=,k=,s=0,s=0,s3=0,sum; for(;i=00;i+) s=s+i; for(;j=50;j+) s=s+j*j; for(;k=00&x000) a=0.0*x;b=0*(0.0*x-a);c=x-00*a-0*b; if(x=(pow(a,3)+pow(b,3)+pow(c,3) printf(%5d,x);x+; 6.7636=+36000 6itsfactorsare