- 76.00 KB
- 2022-04-22 11:48:22 发布
- 1、本文档共5页,可阅读全部内容。
- 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
- 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
- 文档侵权举报电话:19940600175。
'《C程序设计》课后习题答案(4-6章)第四章8、#definePI3.1415926#includevoidmain(){floath,r,l,s,sq,vq,vz;printf("pleaseinputr,h:");scanf("%f,%f",&r,&h);l=2*PI*r;s=r*r*PI;sq=4*PI*r*r;vq=4.0/3.0*PI*r*r*r;vz=PI*r*r*h;printf("l=%6.2fn",l);printf("s=%6.2fn",s);printf("sq=%6.2fn",sq);printf("vq=%6.2fn",vq);printf("vz=%6.2fn",vz);}
9、#includevoidmain(){floatc,f;printf("pleaseinputf:");scanf("%f",&f);c=(5.0/9.0)*(f-32);printf("c:%6.2fn",c);}第五章5、#includevoidmain(){intx,y;printf("pleaseinputx:");scanf("%d",&x);if(x<1){y=x;printf("x=%d,y=x=%dn",x,y);}
elseif(x<10){y=2*x-1;printf("x=%d,y=2*x-1=%dn",x,y);}else{y=3*x-11;printf("x=%d,y=3*x-11=%dn",x,y);}}6、#includevoidmain(){floatscore;chargrade;printf("pleaseinputthestudentscore:");scanf("%f",&score);while((score>100)||(score<0)){printf("error,pleaseinputagain!n");printf("pleaseinputthestudentscore:");scanf("%f",&score);
}switch((int)(score/10)){case10:case9:grade="A";break;case8:grade="B";break;case7:grade="C";break;case6:grade="D";break;case5:case4:case3:case2:case1:case0:grade="E";}printf("scoreis%f,gradeis%cn",score,grade);}7、#include#include
voidmain(){longintnum;intindiv,ten,hundred,thousand,ten_thousand,place;printf("pleaseinputaninteger(0-99999):");scanf("%ld",&num);if(num>9999)place=5;elseif(num>999)place=4;elseif(num>99)place=3;elseif(num>9)place=2;elseplace=1;printf("Totaldigits:%dn",place);printf("Foreachnumber:");ten_thousand=num/10000;thousand=(int)(num-ten_thousand*10000)/1000;hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
indiv=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);if(ten_thousand!=0)printf("%d,%d,%d,%d,%d",ten_thousand,thousand,hundred,ten,indiv);elseif(thousand!=0)printf("%d,%d,%d,%d",thousand,hundred,ten,indiv);elseif(hundred!=0)printf("%d,%d,%d",hundred,ten,indiv);elseif(ten!=0)printf("%d,%d",ten,indiv);elseprintf("%d",indiv);printf("nThereversenumber:");switch(place){case5:printf("%d%d%d%d%d",indiv,ten,hundred,thousand,ten_thousand);break;case4:printf("%d%d%d%d",indiv,ten,hundred,thousand);
break;case3:printf("%d%d%d",indiv,ten,hundred);break;case2:printf("%d%d",indiv,ten);break;case1:printf("%d",indiv);break;}}8、(1)#includevoidmain(){longi;floatbonus,bon1,bon2,bon3,bon4,bon6,bon10;bon1=100000*0.1;bon2=bon1+100000*0.075;bon4=bon2+200000*0.05;
bon6=bon4+200000*0.03;bon10=bon6+400000*0.015;printf("pleaseinputbonus:");scanf("%ld",&i);if(i<=100000)bonus=i*0.1;elseif(i<=200000)bonus=bon1+(i-100000)*0.075;elseif(i<=400000)bonus=bon2+(i-200000)*0.05;elseif(i<=600000)bonus=bon4+(i-400000)*0.03;elseif(i<=1000000)bonus=bon6+(i-600000)*0.015;elsebonus=bon10+(i-1000000)*0.01;printf("bonus:%10.2fn",bonus);}(2)#includevoidmain(){
longi;floatbonus,bon1,bon2,bon4,bon6,bon10;intbranch;bon1=100000*0.1;bon2=bon1+100000*0.075;bon4=bon2+200000*0.05;bon6=bon4+200000*0.03;bon10=bon6+400000*0.015;printf("pleaseinputbonus:");scanf("%ld",&i);branch=i/100000;if(branch>10)branch=10;switch(branch){case0:bonus=i*0.1;break;case1:bonus=bon1+(i-100000)*0.075;break;case2:case3:bonus=bon2+(i-200000)*0.05;break;case4:
case5:bonus=bon4+(i-400000)*0.03;break;case6:case7:case8:case9:bonus=bon6+(i-600000)*0.015;break;case10:bonus=bon10+(i-1000000)*0.01;}printf("bonusis%fn",bonus);}9、#includevoidmain(){inta,b,c,d,t;printf("pleaseinputfournumber:");scanf("%d,%d,%d,%d",&a,&b,&c,&d);printf("a=%d,b=%d,c=%d,d=%dn",a,b,c,d);if(a>b)
{t=a;a=b;b=t;}if(a>c){t=a;a=c;c=t;}if(a>d){t=a;a=d;d=t;}if(b>c){t=b;b=c;c=t;}if(b>d){t=b;b=d;d=t;}if(c>d){t=c;c=d;d=t;}printf("%d%d%d%dn",a,b,c,d);}10、#include#includevoidmain(){inth=10;float
x1=2,y1=2,x2=-2,y2=2,x3=-2,y3=-2,x4=2,y4=-2,x,y,d1,d2,d3,d4;printf("pleaseinput(x,y):");scanf("%f,%f",&x,&y);d1=sqrt((x-x4)*(x-x4)+(y-y4)*(y-y4));d2=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));d3=sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));d4=sqrt((x-x3)*(x-x3)+(y-y3)*(y-y3));if(d1>1&&d2>1&&d3>1&&d4>1)h=0;printf("height%dn",h);}第六章1、#includevoidmain(){intp,r,n,m,temp;printf("pleaseinputtwointeger:");scanf("%d,%d",&n,&m);if(nvoidmain(){charc;intletters=0,space=0,digit=0,other=0;printf("pleaseinputstring:n");while((c=getchar())!="n")
{if((c>="a"&&c<="z")||(c>="A"&&c<="Z"))letters++;elseif(c=="")space++;elseif(c>="0"&&c<="9")digit++;elseother++;}printf("letters:%dnspace:%dndigit:%dnother:%dn",letters,space,digit,other);}3、#includevoidmain(){inta,n;inti=1,sn=0,tn=0;printf("pleaseinputa,n:");scanf("%d,%d",&a,&n);while(i<=n)
{tn=tn+a;sn=sn+tn;a=a*10;++i;}printf("a+aa+aaa+^^^^^=%dn",sn);}4、#includevoidmain(){floats=0,t=1;intn;for(n=1;n<=20;n++){t=t*n;s=s+t;}printf("1!+2!+^^^^^^^^+20!=%en",s);}
5、#includevoidmain(){intn1=100,n2=50,n3=10;floatk;floats1=0,s2=0,s3=0;for(k=1;k<=n1;k++)s1=s1+k;for(k=1;k<=n2;k++)s2=s2+k*k;for(k=1;k<=n3;k++)s3=s3+1/k;printf("sum=%fn",s1+s2+s3);}6、#includevoidmain(){inti,j,k,n;printf("nnarcissusnumberare");
for(n=100;n<1000;n++){i=n/100;j=(n-100*i)/10;k=n-100*i-10*j;if(n==i*i*i+j*j*j+k*k*k)printf("%d",n);}}7、#includevoidmain(){intm,s,i;for(m=2;m<1000;m++){s=0;for(i=1;ivoidmain(){inti,t,n=20;floata=2,b=1,s=0;for(i=1;i<=n;i++){s=s+a/b;t=a;a=a+b;b=t;}printf("sum=%fn",s);}9、
#includevoidmain(){floatsn=100,hn=sn/2;intn;for(n=2;n<=10;n++){sn=sn+2*hn;hn=hn/2;}printf("tentharriveat%fmeter.n",sn);printf("tenth%fmeter.n",hn);}10、#includevoidmain(){intday,x1,x2;day=9;x2=1;while(day>0)
{x1=(x2+1)*2;x2=x1;day--;}printf("total=%dn",x1);}11、#include#includevoidmain(){floata,x0,x1;printf("Enterapositivenumber:");scanf("%f",&a);x0=a/2;x1=(x0+a/x0)/2;do{x0=x1;x1=(x0+a/x0)/2;}while(fabs(x0-x1)>=1e-5);
printf("Thesquarerootof%fis%fn",a,x1);}12、#include#includevoidmain(){floatx1,x0,f,f1;x1=1.5;do{x0=x1;f=((2*x0-4)*x0+3)*x0-6;f1=(6*x0-8)*x0+3;x1=x0-f/f1;}while(fabs(x1-x0)>=1e-5);printf("Therootofequationis%fn",x1);}13、#include
#includevoidmain(){floatx0,x1,x2,fx0,fx1,fx2;do{printf("Enterx1andx2:");scanf("%f,%f",&x1,&x2);fx1=x1*((2*x1-4)*x1+3)-6;fx2=x2*((2*x2-4)*x2+3)-6;}while(fx1*fx2>0);do{x0=(x1+x2)/2;fx0=x0*((2*x0-4)*x0+3)-6;if((fx0*fx1)<0){x2=x0;fx2=fx0;}else{x1=x0;fx1=fx0;}}while(fabs(fx0)>=1e-5);
printf("x=%fn",x0);}14、#includevoidmain(){inti,j,k;for(i=0;i<=3;i++){for(j=0;j<=2-i;j++)printf("");for(k=0;k<=2*i;k++)printf("*");printf("n");}for(i=0;i<=2;i++){for(j=0;j<=i;j++)printf("");for(k=0;k<=4-2*i;k++)printf("*");printf("n");}
}15、#includevoidmain(){chari,j,k;/*i是A的对手;j是B的对手;k是C的对手*/for(i="X";i<="Z";i++)for(j="X";j<="Z";j++)for(k="X";k<"Z";k++)if(i!=j&&i!=k&&j!=k)if(i!="X"&&k!="X"&&k!="Z")printf("A--%ctB--%ctC--%cn",i,j,k);}'
您可能关注的文档
- xml习题1答案(南信大专用).doc
- XML基础教程课后习题解答.doc
- x《初级会计电算化》习题六(含答案解析).doc
- zhujiao054+《民事诉讼法学》习题答案.doc
- [高中政治]《经济生活》第1单元考点练习题[含参考答案].doc
- 《ARM嵌入式系统结构与编程》课后习题答案.doc
- 《ASPNET动态网站开发教程(第三版)》各章习题参考答案.doc
- 《AutoCAD简明教程》第2版-习题答案.doc
- 《C++程序设计教程 第2版》教学素材习题04答案.doc
- 《C程序设计》课后习题答案(第8章).doc
- 《C语言》期末考试模拟复习题一(含答案).doc
- 《C语言程序设计(何钦铭 颜晖 主编)》习题8答案.doc
- 《C语言程序设计》第6章习题答案.doc
- 《C语言程序设计案例教程》练习题答案.docx
- 《EDA技术与VHDL基础》课后习题答案.doc
- 《IBM-PC汇编语言程序设计 第二版》部分习题答案(第5章).doc
- 《JavaScript 程序设计基础教程(第2版)》习题答案.doc
- 《JavaWeb程序开发入门》课后练习(含答案).docx
相关文档
- 施工规范CECS140-2002给水排水工程埋地管芯缠丝预应力混凝土管和预应力钢筒混凝土管管道结构设计规程
- 施工规范CECS141-2002给水排水工程埋地钢管管道结构设计规程
- 施工规范CECS142-2002给水排水工程埋地铸铁管管道结构设计规程
- 施工规范CECS143-2002给水排水工程埋地预制混凝土圆形管管道结构设计规程
- 施工规范CECS145-2002给水排水工程埋地矩形管管道结构设计规程
- 施工规范CECS190-2005给水排水工程埋地玻璃纤维增强塑料夹砂管管道结构设计规程
- cecs 140:2002 给水排水工程埋地管芯缠丝预应力混凝土管和预应力钢筒混凝土管管道结构设计规程(含条文说明)
- cecs 141:2002 给水排水工程埋地钢管管道结构设计规程 条文说明
- cecs 140:2002 给水排水工程埋地管芯缠丝预应力混凝土管和预应力钢筒混凝土管管道结构设计规程 条文说明
- cecs 142:2002 给水排水工程埋地铸铁管管道结构设计规程 条文说明