C语言程序设计第四五六章习题和课堂测试答案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

C语言程序设计第四五六章习题和课堂测试答案,还有期末C语言复习例题//3--1矩形面积#includestdio.hvoidmain(){floata,b;floatc,area;printf(n\PleaseInputa,b:);scanf(%f%f,&a,&b);c=(a+b)*2;area=a*b;printf(c=%f,area=%f\n,c,area);}//3--2输入三位数,输出它各个数位上的数字#includestdio.hvoidmain(){intm,a,b,c;printf(\nPleaseInput三位整数:);scanf(%d,&m);a=m/100;b=m/10%10;c=m%10;printf(a=%d,b=%d,c=%d\n,a,b,c);}//3--3大写字母转换#includestdio.hvoidmain(){charch;printf(\nPleaseInput大写字母:);scanf(%c,&ch);ch=(ch='A'&&ch='Z')?ch=ch+32:ch;printf(ch=%c\n,ch);}//3--3大写字母转换方法二#includestdio.hvoidmain(){charch;printf(\nPleaseInput大写字母:);scanf(%c,&ch);if(ch='A'&&ch='Z')ch=ch+32;printf(ch=%c\n,ch);}//4--1已知圆半径和高,求周长,面积,表面积,体积和圆柱体积#definePI3.14#includemath.h#includestdio.hvoidmain(){doubler,h,c,area,s,v,u;printf(\n请输入圆的半径和高:);scanf(%lf%lf,&r,&h);c=2*PI*r;area=PI*pow(r,2);s=4*PI*pow(r,2);v=4.0/3*PI*pow(r,3);u=PI*pow(r,2)*h;printf(c=%lf,area=%lf,s=%lf,v=%lf,u=%lf\n,c,area,s,v,u);}//4--2输入华氏温度求摄氏温度#includestdio.hvoidmain(){floatF,C;printf(\n请输入F:);scanf(%f,&F);C=(F-32)*5/9;printf(C=%f\n,C);}//4--3输入五位整数,将它反向输出#includestdio.hvoidmain(){intm,a,b,c,d,e,f;printf(请输入五位整数:);scanf(%d,&m);a=m/10000;b=(m-a*10000)/1000;c=(m-a*10000-b*1000)/100;d=(m-a*10000-b*1000-c*100)/10;e=m-a*10000-b*1000-c*100-d*10;f=e*10000+d*1000+c*100+b*10+a;printf(%d对调后是%d\n,m,f);}//4--4人口#includemath.h#includestdio.hvoidmain(){doublen,r;r=0.8/100;n=log(2)/log(r+1);printf(\n%lf年后我国人口超过26亿,n);}//4--5求二点间的距离#includemath.h#includestdio.hvoidmain(){floatx1,y1,x2,y2,l;printf(请输入平面坐标系中二个点的坐标x1y1x2y2:);scanf(%f%f%f%f,&x1,&y1,&x2,&y2);l=pow(pow(x1-x2,2)+pow(y1-y2,2),0.5);printf(二点之间的距离为l=%f\n,l);}//求两点间的距离方法2#includemath.h#includestdio.hvoidmain(){floatx1,y1,x2,y2,l;printf(请输入平面坐标系中二个点的坐标x1y1x2y2:);scanf(%f%f%f%f,&x1,&y1,&x2,&y2);l=sqrt(pow(x1-x2,2)+pow(y1-y2,2));printf(二点之间的距离为l=%f\n,l);}//4--6矩形草坪,求所需时间#defineV0.18#includestdio.hvoidmain(){floata,b,t;printf(请输入矩形草坪的长和宽:);scanf(%f%f,&a,&b);t=a*b/V;printf(所需时间t=%f\n,t);}//4--7实发工资#includestdio.hvoidmain(){inta;doubleb,m;printf(请输入基本工资a=800和本月的营业额b:\n);scanf(a=%d%lf,&a,&b);m=a+b*5.0/100;printf(实发工资为%lf元,m);}//4--8冰箱断电后温度#includestdio.hvoidmain(){doublea,b,t,T;printf(请输入冰箱断电后的小时数a和分钟数b:);scanf(%lf%lf,&a,&b);t=a+b/60;T=4*t*t/(t+2)-20;printf(断电%lf小时后冰箱内的温度为%lf摄氏度,t,T);}//4--9社区人数#includestdio.hvoidmain(){intm;doublea,b;printf(请输入社区的人数m:);scanf(%d,&m);a=(15-2)*14*(float)m/3;b=a/1000*3.4*365*10-1000*(float)m/3;printf(每天节约的用水量为%lf升,节约的开销为%lf元,a,b);}//5--1输入整数,判断其是否能同时被6,9,14整出。#includestdio.hvoidmain(){inta;scanf(%d,&a);if(a%6==0&&a%9==0&&a%14==0)printf(能同时被6,9,14整除\n);elseprintf(不能同时被6,9,14整除\n);}//5--2输入一个年号,判断该年号是否闰年#includestdio.hvoidmain(){longa;printf(\n请输入一个年号:)scanf(%ld,&a);if((a%4==0&&a%100!=0)||(a%400==0))printf(是闰年\n);elseprintf(不是闰年\n);}//5--3.将4个变量由大到小排列#includestdio.hvoidmain(){floata,b,c,d,t;scanf(%f%f%f%f,&a,&b,&c,&d);if(ab){t=a,a=b,b=t;}if(ac){t=a,a=c,c=t;}if(ad){t=a,a=d,d=t;}if(bc){t=b,b=c,c=t;}if(bd){t=b,b=d,d=t;}if(cd){t=c,c=d,d=t;}printf(a=%fb=%fc=%fd=%f,a,b,c,d);}//5--4.输入一个字符,判断其类型#includestdio.hvoidmain(){chara;scanf(%c,&a);if(48=a&&a=57)printf(a是数字);elseif(65=a&&a=90)printf(a是大写字母);elseif(97=a&&a=122)printf(a是小写字母);elseprintf(a是其他字符);}//5--5输入X,求f(x);#includestdio.hvoidmain(){floatx,y;scanf(%f,&x);if(x0)y=2*x-1;elseif(x=0&&x10)y=2*x+10;elseif(x=10&&x100)y=2*x+100;elsey=x*x;printf(%g\n,y);}//5--6.输入a,b,按公式计算Y;#includestdio.h#includemath.hvoidmain(){floata,b,y;printf(\npleaseinputa,b:);scanf(%f%f,&a,&b);if(a0&&b0)y=log(a)+log(b);elseif(a0&&b=0)y=sin(a)+sin(b);elseif(0=a)y=sin(a)+cos(b);printf(y=%f\n,y);}//5--7.输入分子和分母,判断其满足题意条件否。#includestdio.hvoidmain(){inta,b,x,y;scanf(%d%d,&a,&b);x=a/10;y=b%10;if((a%10)==(b/10)){if((1.0*a/b)==(1.0*x/y))printf(符合条件\n);elseprintf(不符合条件\n);}elseprintf(不符合条件\n);}//5--8输入3位整数,判断满足条件否#includestdio.hvoidmain(){intx,a,b,c,y;scanf(%d,&x);y=x/9;a=x/100;b=x/10%10;c=x%10;if(y==a*a+b*b+c*c)printf(符合条件\n);elseprintf(不符合条件\n);}//5--9.判断2位整数是否为守形数#includestdio.hvoidmain(){intx,a,b,c,y;scanf(%d,&x);y=x*x;a=y/10%10;b=x%10;c=10*a+b;if(x==c)printf(是守形数\n);//99de2cifangelseprintf(不是守形数\n);}//5--10输入上衣和裤子数目,计算收款总额#includestdio.hvoidmain(){inta,b,x,y;scanf(%d%d,&a,&b);if(a=50&&b=50){if(ab)y=80*b+60*(a-b);elsey=80*a+45*(b-a);}elseif(ab)y=90*b+60*(a-b);elsey=90*a+45*(b-a);printf(%d\n,y);}//5--11.计算输出税金#includestdio.hvoidmain(){floatx,y;scanf(%f,&x);if(x=10000)y=x*0.05;elseif(x=5000&&x10000)//这里只需X=5000就行了y=x*0.03;elseif(x=1000&&x5000)y=x*0.02;elsey=0;printf(%g\n,y);}//5--12.计算个人所得税金额#includestdio.hvoidmain(){floata,b,c,d,e,f,g,h,i,j,x,y;printf(Pleaseinputa\n:);scanf(%f,&a);b=0.05*(a-1600);c=0.1*(a-2100);d=0.15*(a-3600);e=0.2*(a-6600);f=0.25*(a-21600);g=0.3*(a-41600);h=0.35*(a-61600);i=0.4*(a-81600);j=0.45*(a-101600);x=a/1000;if(x=1.6){y=0;}if(1.6x&&x=2.1){y=b;}elseif(2.1x&&x=3.6){y=25+c;}elseif(3.6x&&x=6.6){y=25+150+d;}elseif(6.6x&&x=21.6){y=25+150+450+e;}elseif(21.6x&&x=41.6){y=25+150+450+3000+f;}elseif(41.6x&&x=61.6){y=25+150+450+3000+5000+g;}elseif(61.6x&

1 / 52
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功