请用c语言程序设计题目:从键盘输入圆柱体的半径和高,求圆柱体的体积和表面积并输出,输出时取2位小数。
时间: 2023-04-04 08:04:51 浏览: 146
#include <stdio.h>
#define PI 3.1415926
int main()
{
float r, h, v, s;
printf("请输入圆柱体的半径和高:\n");
scanf("%f%f", &r, &h);
v = PI * r * r * h;
s = 2 * PI * r * (r + h);
printf("圆柱体的体积为:%.2f\n", v);
printf("圆柱体的表面积为:%.2f\n", s);
return 0;
}
相关问题
c语言编写一个程序,实现输入圆柱体的底面半径和高,输出圆柱体的表面积和体积
好的,这是一个关于圆柱体表面积和体积的计算程序。请看下面的 C 代码实现:
```
#include <stdio.h>
int main()
{
double radius, height, surface_area, volume;
printf("请输入圆柱体的底面半径和高:\n");
scanf("%lf %lf", &radius, &height);
surface_area = 2 * 3.14 * radius * height + 2 * 3.14 * radius * radius;
volume = 3.14 * radius * radius * height;
printf("圆柱体的表面积为:%lf\n", surface_area);
printf("圆柱体的体积为:%lf\n", volume);
return 0;
}
```
当你输入圆柱底面的半径和高时,程序将计算出圆柱体的表面积和体积并输出。希望这个程序能对你有所帮助。
用C语言输入圆柱体的半径和高,求圆柱体的表面积和体积
```c
#include <stdio.h>
int main() {
float radius, height, surface_area, volume;
const float pi = 3.1415926;
printf("Enter the radius of the cylinder: ");
scanf("%f", &radius);
printf("Enter the height of the cylinder: ");
scanf("%f", &height);
surface_area = 2 * pi * radius * height + 2 * pi * radius * radius;
volume = pi * radius * radius * height;
printf("The surface area of the cylinder is: %f\n", surface_area);
printf("The volume of the cylinder is: %f\n", volume);
return 0;
}
```
说明:
- 定义了 `radius`、`height`、`surface_area` 和 `volume` 四个变量,分别表示圆柱体的半径、高、表面积和体积。
- 定义了常量 `pi`,用于存储圆周率的值。
- 使用 `printf` 和 `scanf` 分别输入和输出数据。
- 根据圆柱体的公式,计算出圆柱体的表面积和体积。
- 使用 `printf` 输出结果。
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)