资源描述:
《程序设计技术习题(编程题)参考答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、《程序设计技术》(第三版)习题参考答案及说明习题1四、程序设计题//xt010401.cpp#include#definePI3.1415926voidmain(){doubler,h;printf("请输入半径r和高h:");scanf("%lf,%lf",&r,&h);printf("圆半径:%lf",2*PI*r);printf("圆面积:%lf",PI*r*r);printf("圆球表面积:%lf",4*PI*r*r);printf("圆球体积:%lf",4.0/3*PI*r*r
2、);printf("圆柱体积:%lf",PI*r*r*h);}//xt010402.cpp#includevoidmain(){intc;printf("Inputacharacter:");c=getchar();printf("%ct%d",c,c);}//xt010403.cpp#includevoidmain(){intx,y,h=30,f=90;x=(4*h-f)/2;y=(f-2*h)/2;printf("鸡:%d,兔:%d",x,y);}//xt010404
3、.cpp#include#includevoidmain(){doublea,b,c,s,area;printf("请输入三角形的三条边长(注意三条边长应能够构成三角形):");scanf("%lf,%lf,%lf",&a,&b,&c);s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*(s-c));printf("三角形的面积是:%lf",area);}//xt010405.cpp#includevoidmain(){doublef,c;pr
4、intf("请输入华氏温度:");scanf("%lf",&f);c=5.0/9.0*(f-32);printf("与华氏温度%.2lf对应的摄氏温度是:%.2lf",f,c);}//xt010406.cpp#includevoidmain(){charc1,c2,c3,c4,c5;printf("请输入需加密的字符串(5个字符):");c1=getchar();c2=getchar();c3=getchar();c4=getchar();c5=getchar();printf("加密后的字符串是:
5、");putchar(c1+5);putchar(c2+5);putchar(c3+5);putchar(c4+5);putchar(c5+5);printf("");}习题2四、程序设计题/*xt020401.cpp*/#includevoidmain(){intnum;printf("****Inputnum:****");scanf("%d",&num);if(num%3==0&&num%5==0&&num%7==0)printf("**YES!**");elseprintf("**N
6、O!**");}/*xt020402.cpp*/#includevoidmain(){inth=15;floatx1=2,y1=2,x2=-2,y2=2,x3=-2,y3=-2,x4=2,y4=-2,x,y,d1,d2,d3,d4;printf("***input:x,y***");scanf("%f,%f",&x,&y);d1=(x-x4)*(x-x4)+(y-y4)*(y-y4);/*点(x,y)到各中心点的距离*/d2=(x-x1)*(x-x1)+(y+y1)*(y+y1);d3=(x-x
7、2)*(x-x2)+(y-y2)*(y-y2);d4=(x+x3)*(x+x3)+(y+y3)*(y+y3);if(d1>1&&d2>1&&d3>1&&d4>1)/*判断该点是否在塔外*/h=0;printf("x=%f,y=%f",x,y);printf("h=%d",h);}调试该程序时请输入两组数据:0.5,0.72.1,2.3/*xt020403.cpp*/#includevoidmain(){inti,j,k,n;for(n=100;n<=999;n++){i=n/100;j=n/10
8、-i*10;k=n%10;if(n==i*i*i+j*j*j+k*k*k)printf("%d",n);}}/*xt020404.cpp*/#include#include#defineEPS1.0e-6voidmain(){floate=1,t;longintj=1,n=1;d