如何使用C编程语言计算球体的体积?
球体的体积不过是形状的容量。
球体公式的体积是-
$$V\:=\:\frac{4}{3}\Pi\:r^{3}$$
算法
Step 1: Enter radius of sphere at runtime
Step 2: Apply the formula to variable
Volume=(4/3)*3.14*rad*rad*rad
Step 3: print the volume
Step 4: stop方案一
#include输出结果int main(){ float vol; int rad; rad=20; vol=((4.0f/3.0f) * (3.1415) * rad * rad * rad); printf("the volume of a sphere is %f\n",vol); return 0; }
the volume of a sphere is 33509.335938
方案二
以下是查找球体体积和表面积的示例-
#include输出结果#include int main(){ float rad; float area, vol; printf("Enter radius of the sphere : \n"); scanf("%f", &rad); area = 4 * (22/7) * rad * rad; vol = (4.0/3) * (22/7) * rad * rad * rad; printf("Surface area of sphere is: %.3f", area); printf("\n Volume of sphere is : %.3f", vol); return 0; }
Enter radius of the sphere : 4 Surface area of sphere is: 192.000 Volume of sphere is : 256.000
热门推荐
10 订婚新发言简短祝福语
11 最真的新春祝福语简短
12 18岁简短祝福语经典
13 生日牌祝福语英语简短
14 结婚多层蛋糕祝福语简短
15 友谊晚上祝福语大全简短
16 情人表白祝福语简短大气
17 祝寿时祝福语简短精辟
18 老人掉牙祝福语简短语