-
Notifications
You must be signed in to change notification settings - Fork 0
/
函数求球体,圆柱,圆锥体积.cpp
63 lines (62 loc) · 990 Bytes
/
函数求球体,圆柱,圆锥体积.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#define PI 3.14
void menu();
float vol_ball(int);
float vol_cylind(int,int);
float vol_cone(int,int);
int main ()
{
menu();
return 0;
}
void menu()
{
int t;
float r,h;
while(1)
{
printf(" 1-求球体的体积\n 2-求圆柱体的体积\n 3-求圆锥的体积\n 其他-退出程序\n 请输入命令:");
scanf("%d",&t);
if(t<1||t>3)
{
printf("已退出程序");
break;
}
switch (t)
{
case 1 :
printf("请输入半径:");
scanf("%f",&r);
printf("%f\n",vol_ball(r));
break ;
case 2:
printf("请输入半径和高度");
scanf("%f %f",&r,&h);
printf("%f\n",vol_cylind(r,h));
break;
case 3:
printf("请输入半径和高度");
scanf("%f %f");
printf("%f\n",vol_cone(r,h));
break;
}
}
}
float vol_ball(int r)
{
float vol;
vol=4*PI*r*r*r/3;
return vol;
}
float vol_cylind(int r ,int h)
{
float vol;
vol=h*PI*r*r;
return vol;
}
float vol_cone(int r,int h)
{
float vol;
vol=h*PI*r*r/3.0;
return vol;
}