您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > C语言程序设计(第三版)课后习题答案
C程序设计(第三版)答案-谭浩强程序是在VC6.0下编译的,所以头文件和TC的不太一样!4-8#includeiostream#definepi3.1415voidmain(){floatr,h,rl,ra,ss,sv,cv;printf(输入圆的半径和圆柱的高\n\n);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\n\n圆面积为:%f\n\n圆球表面积为:%f\n\n圆球体积为:%f\n\n圆柱体积为:%f\n\n,rl,ra,ss,sv,cv);}4-9#includeiostreamvoidmain(){floatF,c;printf(输入一个华氏温度\n\n);scanf(%f,&F);c=5*(F-32)/9;printf(摄氏温度为:%.2f\n\n,c);}第五章5-4#includeiostreamvoidmain(){inta,b,c,max;printf(输入三个整数a,b,c\n\n);scanf(%d%d%d,&a,&b,&c);if(ab)max=a;elsemax=b;if(maxc)max=c;printf(最大的数为:%d\n\n,max);}5-5#includeiostreamvoidmain(){floatx,y;printf(输入x\n\n);scanf(%f,&x);if(x1)y=x;elseif(x10)y=2*x-1;elsey=3*x-11;printf(y=%f\n\n,y);}5-6#includeiostreamvoidmain(){floatm;intn;printf(输入成绩\n\n);scanf(%f,&m);n=m/10;switch(n){case0:case1:case2:case3:case4:case5:printf(E\n\n);break;case6:printf(D\n\n);break;case7:printf(C\n\n);break;case8:printf(B\n\n);break;case9:case10:printf(A\n\n);break;}}5-7#includeiostream#includemath.hvoidmain(){inta,b,c,i,j,n;printf(输入五位正整数\n\n);scanf(%d,&a);printf(\n\n);c=a;for(i=1;;i++){b=c%10;c=c/10;printf(%d,b);if(c==0){printf(\n\n);printf(正整数为%d位数\n\n,i);break;}}c=a;for(j=i-1;j=0;j--){n=pow(10,j);b=c/n;c=c%n;printf(%d\n,b);}}5-8if语句:#includeiostreamvoidmain(){intI;floatbonus;printf(输入当月利润I\n\n);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=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\n\n,bonus);}switch语句:#includeiostreamvoidmain(){intI,n;floatbonus;printf(输入当月利润I\n\n);scanf(%d,&I);if(I1000000)n=10;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:bonus=10000+7500+10000+6000+(I-600000)*1.5/100;break;case10:bonus=10000+7500+10000+6000+6000+(I-1000000)*1/100;break;}printf(应发奖金数为:%f\n\n,bonus);}5-9#includeiostreamvoidmain(){inta,b,c,d,temp,min;printf(输入四个数a,b,c,d\n\n);scanf(%d%d%d%d,&a,&b,&c,&d);if(ab){temp=a;a=b;b=temp;}if(ac){temp=a;a=c;c=temp;}if(ad){temp=a;a=d;d=temp;}printf(由小到大排列为:\n\n);printf(%d,a);if(bc){temp=b;b=c;c=temp;}if(bd){temp=b;b=d;d=temp;}printf(%d,b);if(cd){temp=c;c=d;d=temp;}printf(%d,c);printf(%d,d);}5-10#includeiostream#includemath.hvoidmain(){floatx,y,a,b,c,d;printf(输入点的坐标\n\n);scanf(%f%f,&x,&y);a=sqrt((2-x)*(2-x)+(2-y)*(2-y));b=sqrt((2-x)*(2-x)+(-2-y)*(-2-y));c=sqrt((-2-x)*(-2-x)+(-2-y)*(-2-y));d=sqrt((-2-x)*(-2-x)+(2-y)*(2-y));if(a=1||b=1||c=1||d=1)printf(该点建筑高度为:10m);elseprintf(该点建筑高度为:0m);}第六章:6-1#includeiostream#includemath.hvoidmain(){intm,n,max,min,i,k;printf(输入两个正整数\n\n);scanf(%d%d,&m,&n);if(mn)k=n;elsek=m;for(i=1;i=k;i++){if((m%i==0)&&(n%i==0))max=i;}printf(最大公约数为:%d\n\n,max);if(mn)k=m;elsek=n;for(i=k;;i++){if((i%m==0)&&(i%n==0)){min=i;break;}}printf(最小公倍数为:%d\n\n,min);}6-2#includeiostreamvoidmain(){charc;intl=0,b=0,n=0,e=0;printf(输入一行字符\n\n);while((c=getchar())!='\n'){if((c='a'&&c='z')||(c='A'&&c='Z'))l+=1;elseif(c=='')b+=1;elseif(c=48&&c=57)n+=1;elsee+=1;}printf(英文字母个数为:%d\n\n空格个数为:%d\n\n数字个数为:%d\n\n其他字符个数为:%d\n\n,l,b,n,e);}6-3#includeiostream#includemath.hvoidmain(){intn,k,i;floata,s=0;printf(输入n和a\n\n);scanf(%d%f,&n,&a);for(i=0;in;i++){k=pow(10,i);s=s+(n-i)*a*k;}printf(和s=%f\n\n,s);}6-4#includeiostreamvoidmain(){intn,s,S=0,i,j;printf(输入n\n\n);scanf(%d,&n);for(i=1;j=n;i++){s=1;for(j=1;j=i;j++){s=s*j;}S+=s;}printf(和S=%d\n\n,S);}6-5#includeiostreamvoidmain(){inti,m,n,t;ints1=0,s2=0;floats3=0,s,l;printf(输入m,n,t的值\n\n);scanf(%d%d%d,&m,&n,&t);for(i=1;i=m;i++){s1+=i;}for(i=1;i=n;i++){s2+=i*i;}for(i=1;i=t;i++){l=1.0/i;s3+=l;}s=s1+s2+s3;printf(和s=%f,s);}6-6#includeiostreamvoidmain(){intm,n,k,i,j;printf(水仙花数为:\n);for(i=100;i=999;i++){j=i;m=j%10;j=j/10;n=j%10;k=j/10;if(i==m*m*m+n*n*n+k*k*k)printf(%d,i);}}6-7#includeiostream#includemath.hvoidmain(){inti,j,k,s;for(i=1;i=1000;i++){s=0;for(j=1;ji;j++){if(i%j==0)s+=j;}if(s==i){printf(\n\n);printf(%ditsfactorsare,i);for(j=1;ji;j++){if(i%j==0)printf(%d,j);}}}}6-8#includeiostreamvoidmain(){intn,i;floatf1,f2,s,temp;printf(输入n\n\n);scanf(%d,&n);f1=2.0;f2=3.0;s=f1;for(i=1;i=n-1;i++){s+=f2/f1;temp=f2;f2=f1+f2;f1=temp;}printf(前%d项和为%f,n,s);}6-9#includeiostream#includemath.hvoidmain(){inti,n,l=100;floatm,s=0;printf(输入n\n\n);scanf(%d,&n);m=l;for(i=1;i=n;i++){s+=2*m;m=m*0.5;}printf(第%d次落地时经过%f米\n\n,n,s-l);printf(第%d次落地后反弹%f米\n\n,n,m);}6-10#includeiostreamvoidmain(){intm=1,n,i;printf(输入n\n\n);scanf(%d,&n);for(i=1;in;i++){m=(m+1)*2;}printf(一共摘了%d个桃子\n\n,m);}6-11#includeiostream#includemath.hvoidmain(){floata,x1,x2;printf(输入a\n\n);scanf(%f,&a);x1=a/2;loop:x2=(x1+a/x1)/2;if(fabs(x1-x2)1e-5){x1=x2;gotoloop;}elseprintf(\n\na的平方根为%f\n\n,x2);}6-12#includeiostream#includemath.hvoidmain
本文标题:C语言程序设计(第三版)课后习题答案
链接地址:https://www.777doc.com/doc-2645281 .html