输入样例
1
2
3
2.4 3
0
输出样例
1-Ball
2-Cylinder
3-Cone
other-Exit
Please enter your command:
Please enter the radius:
33.51
1-Ball
2-Cylinder
3-Cone
other-Exit
Please enter your command:
Please enter the radius and the height:
18.10
1-Ball
2-Cylinder
3-Cone
other-Exit
Please enter your command:
#include<stdio.h>
double Cone(double r,double h);
double Cylinder(double r,double h);
double ball(double r);
void print();
int main(){
int a,cnt=0;
double r,h;
while(1){
print();
scanf("%d",&a);
if(a==1){
printf("Please enter the radius:\n");
scanf("%lf",&r);
ball(r);
}else if(a==2){
printf("Please enter the radius and the height:\n");
scanf("%lf %lf",&r,&h);
Cylinder(r,h);
}else if(a==3){
printf("Please enter the radius and the height:\n");
scanf("%lf %lf",&r,&h);
Cone(r,h);
}else{
break;
}
}
}
void print(){
printf("1-Ball\n");
printf("2-Cylinder\n");
printf("3-Cone\n");
printf("other-Exit\n");
printf("Please enter your command:\n");
}
double ball(double r){
double v;
v=4.0/3.0*3.1415926535*r*r*r;
printf("%.2f\n",v);
}
double Cylinder(double r,double h){
double v;
v=3.1415926535*r*r*h;
printf("%.2f\n",v);
}
double Cone(double r,double h){
double v;
v=(3.1415926535*r*r*h)/3.0;
printf("%.2f\n",v);
}
可以直接主函数操作就行,这里是练习以下调用函数
自己的注意点
pi的精度3.1415926535,否则差4分的测试点,卡了好久
类型和变量一定一定要匹配对应,比如我的定义输入的是int型,运行输入时是double的数字,就出现疯狂死循环,我还在找是不是while出错了