#代码如下:
#include<stdio.h>
#include<math.h>
void ball(int k){
double r;
printf("Please enter the radius:\n");
scanf("%lf",&r);
printf("%.2f\n",4.0/3*3.1415926*pow(r,3));
printf("1-Ball\n2-Cylinder\n3-Cone\nother-Exit\nPlease enter your command:\n");
}
void squre(int k){
double r,h;
printf("Please enter the radius and the height:\n");
scanf("%lf%lf",&r,&h); //测试数据:
1
2
3
2.4 3
0
printf("%f %f",r,h); //这个是用来看r和h的数值,结果显示r=3 h=2.4 好困惑!!!
if(k==2) printf("%.2f\n",3.1415926*pow(r,2)*h);
else printf("%.2f\n",1.0/3*4*pow(r,2)*h);
printf("1-Ball\n2-Cylinder\n3-Cone\nother-Exit\nPlease enter your command:\n");
}
int main(void)
{
int k;
printf("1-Ball\n2-Cylinder\n3-Cone\nother-Exit\nPlease enter your command:\n");
scanf("%d",&k);
switch(k){
case 1: ball(k);
case 2:
case 3: squre(k);
default: break;
}
return 0;
}


