资源描述:
《c语言程序设计答案》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、C语言程序设计答案//3--1矩形面积#includevoidmain(){floata,b;floatc,area;printf("nPleaseInputa,b:");scanf("%f%f",&a,&b);c=(a+b)*2;area=a*b;printf("c=%f,area=%f",c,area);}//3--2输入三位数,输出它各个数位上的数字#includevoidmain(){intm,a,b,c;printf("PleaseInput三位整数:");scanf("%d",&m);a=m/100;b=m/
2、10%10;c=m%10;printf("a=%d,b=%d,c=%d",a,b,c);}//3--3大写字母转换#includevoidmain(){charch;printf("PleaseInput大写字母:");scanf("%c",&ch);ch=(ch>='A'&&ch<='Z')?ch=ch+32:ch;printf("ch=%c",ch);}//3--3大写字母转换方法二#includevoidmain(){charch;printf("PleaseInput大写字母:");scanf("%c",&
3、ch);if(ch>='A'&&ch<='Z')ch=ch+32;printf("ch=%c",ch);}//4--1已知圆半径和高,求周长,面积,表面积,体积和圆柱体积#definePI3.14#include#includevoidmain(){doubler,h,c,area,s,v,u;printf("请输入圆的半径和高:");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
4、)*h;printf("c=%lf,area=%lf,s=%lf,v=%lf,u=%lf",c,area,s,v,u);}//4--2输入华氏温度求摄氏温度#includevoidmain(){floatF,C;printf("请输入F:");scanf("%f",&F);C=(F-32)*5/9;printf("C=%f",C);}//4--3输入五位整数,将它反向输出#includevoidmain(){intm,a,b,c,d,e,f;printf("请输入五位整数:");scanf("%d",&m);a=m/1
5、0000;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",m,f);}//4--4人口#include#includevoidmain(){doublen,r;r=0.8/100;n=log(2)/log(r+1);printf("%lf年后我国人口超过26亿",n);}/
6、/4--5求二点间的距离#include#includevoidmain(){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",l);}//求两点间的距离方法2#include#includevoidmain(){floatx1,y1,x2,y2,l;pr
7、intf("请输入平面坐标系中二个点的坐标x1y1x2y2:");scanf("%f%f%f%f",&x1,&y1,&x2,&y2);l=sqrt(pow(x1-x2,2)+pow(y1-y2,2));printf("二点之间的距离为l=%f",l);}//4--6矩形草坪,求所需时间#defineV0.18#includevoidmain(){floata,b,t;printf("请输入矩形草坪的长和宽:");scanf("%f%f",&a,&b);t=a*b/V;printf("所需时间t=%f",t);}//4--7实发工资#in