酷代码 AI
菜单
服务商

C语言实现:多功能圆形体体积计算器,含球体、圆柱、圆锥体积计算

```c #include <stdio.h> #include <math.h> #define PI 3.14159265358979323846 // 计算球体体积 double ball_volume(double r) { return (4.0 / 3.0) * PI * pow(r, 3); } // 计算圆柱体体积 double cylinder_volume(double r, double h) { return PI * pow(r, 2) * h; } // 计算圆锥体体积 double cone_volume(double r, double h) { return (1.0 / 3.0) * PI * pow(r, 2) * h; } int main() { int command; double r, h; while (1) { printf("1-Ball\n"); printf("2-Cylinder\n"); printf("3-Cone\n"); printf("other-Exit\n"); printf("Please enter your command:\n"); scanf("%d", &command); if (command == 1) { printf("Please enter the radius:\n"); scanf("%lf", &r); printf("%.2lf\n", ball_volume(r)); } else if (command == 2) { printf("Please enter the radius and the height:\n"); scanf("%lf %lf", &r, &h); printf("%.2lf\n", cylinder_volume(r, h)); } else if (command == 3) { printf("Please enter the radius and the height:\n"); scanf("%lf %lf", &r, &h); printf("%.2lf\n", cone_volume(r, h)); } else { break; } } return 0; } ``` ######[AI问答 | 414点数解答 | 2025-12-10 20:34:19]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]