设圆半径r=1.5,圆柱高h=3,求圆周长、圆面积、圆球表面积、圆球体积、圆柱体
积。用scanf输入数据,输出计算结果,输出时要求有文字说明,取小数点后2位数字。请
编程序。
#include <stdio.h> #include "math.h" int main() { //perimeter周长 area面积 surfaceArea表面积 volume体积 float r,h,perimeter,area,surfaceArea,RoundVolume,CylinderVolume; double pi = acos(-1.0); printf("请依次输入圆半径r,圆柱高h的值\n"); scanf("%f %f",&r,&h); //求圆周长 perimeter = 2*pi*r; //求圆面积 area = pi*r*r; //圆球表面积 surfaceArea = 4*pi*r*r; //圆球体积 RoundVolume = 4/3*pi* pow(r,3); //圆柱体积 CylinderVolume = pi* pow(r,2)*h; printf("圆周长为%0.2f,圆面积为%0.2f," "圆球表面积为%0.2f,圆球体积为%0.2f,圆柱体积为%0.2f", perimeter,area,surfaceArea,RoundVolume,CylinderVolume); return 0; }