设圆的半径r=1.5,圆柱高h=3,求圆周长,圆面积、圆球表面积、圆球体积和圆柱体积。编c语言程序,用scanf输入数据,输出计算结果。输出时要有文字说明,取小数点后两位数字
时间: 2023-05-24 19:06:23 浏览: 107
#include <stdio.h>
#include <math.h>
int main() {
double r, h;
double circular_perimeter, circular_area, sphere_surface_area, sphere_volume, cylinder_volume;
const double PI = 3.1415926;
// 输入
printf("请输入圆的半径r和圆柱高h:\n");
scanf("%lf%lf", &r, &h);
// 计算
circular_perimeter = 2 * PI * r;
circular_area = PI * pow(r, 2);
sphere_surface_area = 4 * PI * pow(r, 2);
sphere_volume = 4.0 / 3.0 * PI * pow(r, 3);
cylinder_volume = circular_area * h;
// 输出
printf("圆的周长为:%.2lf\n", circular_perimeter);
printf("圆的面积为:%.2lf\n", circular_area);
printf("圆球的表面积为:%.2lf\n", sphere_surface_area);
printf("圆球的体积为:%.2lf\n", sphere_volume);
printf("圆柱的体积为:%.2lf\n", cylinder_volume);
return 0;
}
阅读全文