资源描述:
《谭浩强c语言课后题答案.DOC》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、4-8#include#definepi3.1415voidmain(){floatr,h,rl,ra,ss,sv,cv;printf("输入圆的半径和圆柱的高");scanf("%f%f",&r,&h);rl=2*pi*r;ra=pi*r*r;ss=4*pi*r*r;sv=4*pi*r*r*r/3;cv=ra*h;printf("圆周长为:%f圆面积为:%f圆球表面积为:%f圆球体积为:%f圆柱体积为:%f",rl,ra,ss,sv,cv);}4-9#includevoidmain(){float
2、F,c;printf("输入一个华氏温度");scanf("%f",&F);c=5*(F-32)/9;printf("摄氏温度为:%.2f",c);}第五章5-4#includevoidmain(){inta,b,c,max;printf("输入三个整数a,b,c");scanf("%d%d%d",&a,&b,&c);if(a>b)max=a;elsemax=b;if(maxvoidmain(){floatx,y;printf(
3、"输入x");scanf("%f",&x);if(x<1)y=x;elseif(x<10)y=2*x-1;elsey=3*x-11;printf("y=%f",y);}5-6#includevoidmain(){floatm;intn;printf("输入成绩");scanf("%f",&m);n=m/10;switch(n){case0:case1:case2:case3:case4:case5:printf("E");break;case6:printf("D");break;case7:printf("C");b
4、reak;case8:printf("B");break;case9:case10:printf("A");break;}}5-7#include#includevoidmain(){inta,b,c,i,j,n;printf("输入五位正整数");scanf("%d",&a);printf("");c=a;for(i=1;;i++){b=c%10;c=c/10;printf("%d",b);if(c==0){printf("");printf("正整数为%d位数",i);break;}}c=a;for
5、(j=i-1;j>=0;j--){n=pow(10,j);b=c/n;c=c%n;printf("%d",b);}}5-8if语句:#includevoidmain(){intI;floatbonus;printf("输入当月利润I");scanf("%d",&I);if(I<=100000)bonus=I/10;elseif(I<=200000)bonus=10000+(I-100000)*7.5/100;elseif(I<=400000)bonus=10000+7500+(I-200000)*5/100;elseif(I<=600000)bonus=
6、10000+7500+10000+(I-400000)*3/100;elseif(I<=1000000)bonus=10000+7500+10000+6000+(I-600000)*1.5/100;elsebonus=10000+7500+10000+6000+6000+(I-1000000)*1/100;printf("应发奖金数为:%f",bonus);}switch语句:#includevoidmain(){intI,n;floatbonus;printf("输入当月利润I");scanf("%d",&I);if(I>1000000)n=10;
7、elsen=I/100000;switch(n){case0:bonus=I/10;break;case1:bonus=10000+(I-100000)*7.5/100;break;case2:case3:bonus=10000+7500+(I-200000)*5/100;break;case4:case5:bonus=10000+7500+10000+(I-400000)*3/100;break;case6:case7:case8:case9