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]
- Java 实现矩形与长方体类,精准计算底面积与体积(字节豆包 | 319点数解答 | 2024-10-20 10:25:46)292
- Java 实现矩形与长方体类,轻松计算底面积和体积(字节豆包 | 308点数解答 | 2024-10-20 10:34:27)273
- Java 实现矩形与长方体类:计算底面积与体积的完整代码示例(字节豆包 | 306点数解答 | 2024-10-20 18:34:47)277
- Python 实现球类:精准计算半径、表面积与体积,附输入验证与异常处理!(阿里通义 | 261点数解答 | 2024-11-28 21:19:39)352
- Python 实现 DES 加密算法编程实验:从原理到单步调试全解析(字节豆包 | 4096点数解答 | 2025-11-09 22:06:30)75
- Python 代码:计算多个球体与圆柱体的表面积和体积之和(讯飞星火 | 614点数解答 | 2024-06-13 19:29:36)236
- 代码揭秘:栈助力中缀表达式转后缀并精准计算!(字节豆包 | 979点数解答 | 2024-10-12 20:35:40)223
- Java实现:用重载方法精准计算长方体、球体与圆柱体体积 (字节豆包 | 362点数解答 | 2024-11-27 11:02:36)97
- 51 单片机:定时器 0 实现 8 个 LED 循环点亮,附代码及优化建议(字节豆包 | 1193点数解答 | 2024-12-27 15:10:29)323
- Python:用抽象基类实现圆柱体与长方体的表面积和体积计算(讯飞星火 | 472点数解答 | 2024-06-13 19:05:45)254
- C++ 代码实现自定义运算 x@y = x² + y² - xy 及 x@(x+y) 计算(DeepSeek | 215点数解答 | 2025-12-13 15:08:14)80
- C++ 实现根据输入正整数奇偶性计算偶数和或约数和(字节豆包 | 838点数解答 | 2026-02-28 20:23:59)33