酷代码 AI
菜单
服务商

C语言实现:圆形体体积计算器的完整代码与功能解析

```c #include <stdio.h> #define PI 3.1415926 // 计算球体体积 double ball_volume(double r) { return (4.0 / 3.0) * PI * r * r * r; } // 计算圆柱体体积 double cylinder_volume(double r, double h) { return PI * r * r * h; } // 计算圆锥体体积 double cone_volume(double r, double h) { return (1.0 / 3.0) * PI * r * r * 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("%.2f\n", ball_volume(r)); } else if (command == 2) { printf("Please enter the radius and the height:\n"); scanf("%lf %lf", &r, &h); printf("%.2f\n", cylinder_volume(r, h)); } else if (command == 3) { printf("Please enter the radius and the height:\n"); scanf("%lf %lf", &r, &h); printf("%.2f\n", cone_volume(r, h)); } else { break; } } return 0; } ``` ######[AI问答 | 389点数解答 | 2025-12-10 22:58:02]

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