《C语言程序设计第三版谭浩强课后习题答案完整版.docx》由会员分享,可在线阅读,更多相关《C语言程序设计第三版谭浩强课后习题答案完整版.docx(14页珍藏版)》请在第一文库网上搜索。
1、1.5#inc1udevoidmain()printf(*n);printf(,Verygood!n);nrintft*n#inc1udevoidmain()f1oatmax(f1oatx,f1oaty,f1oatz);f1oata,b,c;Printfc请分别输入a,b,c:nn);SCanfC%f,%F,&a,&b,&c);printf(max=%f,max(a,b,c);1f1oatmax(f1oatx,f1oaty,f1oatz)(f1oatm,n;m=xy?x:y;n=mz?m:z;return(n);1请分别输入a,b,c:1.2,2.3,0.6max=2.300000Pressa
2、nykeytocontinue3.6#inc1udevoidmain()charc1=,a,c2=b,c3=c,c4,101,.c5,116,;printf(4ia%cb%ctc%ctabcn,c1,c2,c3);printf(utb%c%cnw,c4,c5);abcaabbccANPressanykeytocontinue#inc1udevoidmain()doub1ex=2.5,y=4.7,z;inta=7;z=x+a%3*(int)(x+y)%24;Printf(该表达式的值为:%,z);唐达式的值为:2.500000Pressanykeytocontinue#inc1udevoidma
3、in()(inta=2,b=3;f1oatx=3.5,y=2.5,z;z=(f1oat)(a+b)2(int)x%(int)y;Primf(该表达式的值为:%,z);该表达式的值3.500000PreSSanykeytoCOStimIe4.5#inc1udevoidmain()(inta=5,b=7;doub1ex=67.8564,y=-789.124;charc=,A,;1ongn=1234567;unsignedu=65535;printf(%d%dn”,a,b);Printf(%3d%3dn”,a,b);printf(%f,%fn*,x,y);printf(-10f,%T0fn”,x,y
4、);printf(%8.2f,%8.2f,%.4f,%.4f,%3f,%3fn”,x,y,x,y,x,y);printf(*%e,%12en*,x,y);printf(%c,%d,%o,%xn”,n,n,n);printf(%1d,%1o,%xn”,n,n,n);printf(,%u,%o,%x,1n”,u,u,u,u);printf(z,%s,%5.3sn,“COMPUTER,COMPUTER);575767.856400,-789.12400067.856400,-789.12400067.86,-789.12,67.8564,-789.1240,67.856400,-789.124000
5、6.785640e+001,-7.89e00271234567,4553207,2521241234567,4553207,12d68765535,177777,ffff,65535COMPUTER,COMPressanykeytocontinueinc1udevoidmain()(inta,b;f1oatx,y;charc1,c2:scanf(a=%db=%d,&a,&b);scanf(%f%e”,&x,&y);SCanf(%c%c”,&c1,&c2);)a=3b=78.57.182e+001AaPressanykeytocontinuea#inc1udevoidmain()(inta,b;
6、f1oatx,y,z;charc1,c2;scanf(%5d%5d,&a,&b);scanf(%f%f%*f%f,&x,&y,&z);scanf(*%c%c*,&c1,&c2);)1020Aa1.5-3.75,67.8Pressanykeytocontinuea#inc1udedefinepi3.14voidmain()f1oatr,h,1,si,s2,v1,v2;Printf(请输入r,h的值:n);scanf(%f,%f,&r,&h);1=2*pi*r;s1=pi*r*r;s2=4*s1;v1=43*pi*r*r*r;v2=s1*h;Printf(圆周长为:%.2fn,1);Printf(
7、圆面积为:%.2fnf,si);Printf(“圆球表面积为:%.2fn”,s2);Printf(圆球体积为:%.2fn*,v1);Printf(圆柱体积为:%.2fnzz,v2);)28.26.60.19tocontinue?.为:ke 积为为为为面篇天春体清员-员-员-回员5.5 #inc1udevoidmain()(f1oatx,y;PrimfC请输入X的值:5);scanf(%,fex);if(x=1&x10)y=2*x-1;e1sey=3*x-11;printf(x与y的值分别为:n%f,%,x,y);printf(n,);1请输入X的值:X与y的值分别为:25.000000,64.
8、000000Pressanykeytocontinue5.6 #inc1udevoidmain()f1oatb;inta;PrinIf(请输入该同学的成绩:n);scanf(,%f,b);whi1e(bIOO)(Prin1fr输入有误,请重新输入:n);scanf(%f,fcb);1a=int(b10);if(a6)a=5;switch(a)(case10:case9:Prin1f(该同学为等级:A*);break;case8:Printf(该同学为等级:B);break;case7:Primf(该同学为等级:C);break;case6:Prin1f(该同学为等级:Dn);break;cas
9、e5:Prin1f(该同学为等级:E);break;请输入该同学的成绩:101输入有误,请重新输入:-2.5输入有误,请重新输入:99.5该同学为等级:APressanykeytocontinue#inc1ude#inc1udevoidmain()intx,y,m,n,i=1,j=0;Primf(请给出一个不多于5位的正整数:n);scanf(%d,&x);whi1e(x=100000)Primf(输入有误n请给出一个不多于5位的正整数:n”);SCanf(%d,&x);)for(n=0;n0&y=0);printf(n逆序输出为n”);do(printf(%d,int(xpow(10,j)%
10、10);j+;)whi1e(j-m0);printf(n);请给出一个不多于5位的正整数:-4鹿人有误i给出一个不多于5位的正整数:123456麻有误请给出一个不多于5位的正整数:14235它是5位数从高到低位依次为14235龙序输出为53241?ressanykeytocontinue6.1 输入两个正整数m和n,求其最大公约数和最小公倍数。#inc1udevoidmain()(intm,n,i,j;Printf(请分别输入m,n的值:n);scanf(%d,%dM,&m,&n);for(i=1;i=m;i+)if(m%i=0&n%i=0)j=i;)Printf(这两个整数的最大公约数是:%
11、d,j);for(i寸;i+)(if(i%m=0&i%n=0)break;)Printf(这两个整数的最小公倍数数是:%d,i);printf(nu);请分另IJ输入m,n的值:15,21这两个整数的最大公约数是:3这两个整数的最小公倍数数是:105Pressanykeytocontinue6.2 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。#inc1udevoidmain()(inti=0j=0,k=0,x=0;charc;Prindr请输入一行字符串:);whi1e(c=getchar()!=,n,)(if(c=,A,fefec=a,fefcc=0,c=,9,)
12、k+;e1sex+;)Printf(英文字母、空格、数字、其他字符的个数分别为:d,%d,%d,%dj,i,j,k,x);printf(n);)懂输入一行字符串:zs123.cu.c.2声文字母、空格、数字、.其他字符的个数分别为:6,2,4,3.Pressanykeytocontinue6.3 求Sn=a+aa+aaa+aaa之值,其中a是一个数字。例如:2+22+222+2222+22222(此时n=5),n由键盘输入。#inc1ude#inc1udevoidmain()(inti,n;intsum=0,s=0;Printf(请输入n的值:n);scanf(%d,fen);whi1e(n1)(Printf(请重新输入n的值:nf);scanf(u%d,&n);1for(i=0;in;i+)(s+=pow(10,i);sum+=2*s;)printf(sum=%dn,sum);)请输入n的值:5Si1m=24690Pressanykeytocontinue6.8题目:有一分数序列2/1,3/2,5/3,8/5,13/8,21/13,