好文档 - 专业文书写作范文服务资料分享网站

C语言程序设计第三版谭浩强课后习题答案完整版

天下 分享 时间: 加入收藏 我要投稿 点赞

1.5

#include void main() {

printf(\

printf(\ Very good! \\n\ printf(\ }

1.6

#include void main() { float max(float x,float y,float z); float a,b,c;

printf(\请分别输入a,b,c:\\n\ scanf(\ printf(\ }

float max(float x,float y,float z) { float m,n; m=x>y? x: y; n=m>z? m: z; return(n); }

3.6

#include void main() {

char c1=’a’,c2=’b’,c3=’c’,c4=’\\101’,c5=’\\116’; printf(“a%c b%c\\tc%c\\tabc\\n”,c1,c2,c3); printf(“\\t\\b%c %c\\n”,c4,c5);

}

3.9.1

#include void main() { double x=2.5,y=4.7,z; int a=7;

z=x+a%3*(int)(x+y)%2/4; printf(\该表达式的值为:%f\

}

3.9.2

#include void main() {

int a=2,b=3;

float x=3.5,y=2.5,z;

z=(float)(a+b)/2+(int)x%(int)y; printf(\该表达式的值为:%f\ }

4.5

#include void main() { int a=5,b=7; double x=67.8564,y=-789.124; char c='A'; long n=1234567; unsigned u=65535; printf(\ printf(\ printf(\ printf(\ printf(\ printf(\ printf(\ printf(\ printf(\

printf(\ }

4.6

#include void main() {

int a,b; float x,y; char c1,c2;

scanf(\scanf(\scanf(\}

4.7

#include void main() {

int a,b; float x,y,z; char c1,c2;

scanf(\

scanf(\scanf(\}

4.8

#include #define pi 3.14 void main() {

float r,h,l,s1,s2,v1,v2;

printf(\请输入r,h的值:\\n\ scanf(\ l=2*pi*r; s1=pi*r*r; s2=4*s1;

v1=4/3*pi*r*r*r; v2=s1*h;

printf(\圆周长为:%.2f\\n\printf(\圆面积为:%.2f\\n\printf(\圆球表面积为:%.2f\\n\printf(\圆球体积为:%.2f\\n\printf(\圆柱体积为:%.2f\\n\}

5.5 #include void main() {

float x,y;

printf(\请输入x的值:\\n\ scanf(\ if(x<1) y=x; else

if(x>=1&&x<10) y=2*x-1; else y=3*x-11;

printf(\与y的值分别为:\\n%f,%f\ printf(\ }

5.6 #include void main()

{ float b; int a;

printf(\请输入该同学的成绩:\\n\ scanf(\ while (b<0||b>100) { printf(\输入有误,请重新输入:\\n\ scanf(\ }

a= int(b/10); if(a<6) a=5; switch(a) { case 10:

case 9: printf(\该同学为等级:A\ case 8: printf(\该同学为等级:B\ case 7: printf(\该同学为等级:C\ case 6: printf(\该同学为等级:D\ case 5: printf(\该同学为等级:E\ } }

#include #include void main() { int x,y,m,n,i=1,j=0;

printf(\请给出一个不多于5位的正整数:\\n\ scanf(\

while(x<=0||x>=100000)

{ printf(\输入有误\\n请给出一个不多于5位的正整数:\\n\ scanf(\ }

for(n=0;n<5;n++) { y=int(x/pow(10,n));

01hx79290y28mww144vu
领取福利

微信扫码领取福利

微信扫码分享