计算球体体积
1 #include <stdio.h> 2 #define PI 3.14 3 int main() 4 { 5 double r,v; 6 while(scanf("%lf",&r)) 7 { 8 v = (3.0/4)*PI*r*r*r; 9 //除法最好留在最后算 10 printf(".3%lf\n",v); 11 } 12 return 0; 13 }
参考c++
1 #include <math.h> 2 #include <stdio.h> 3 4 #define PI 3.1415927 5 6 int main(void) 7 { 8 double r; 9 10 while (scanf("%lf", &r) != EOF) 11 printf("%.3lf\n", 4.0*PI*r*r*r/3.0); 12 13 return 0; 14 }
时间: 2024-10-23 19:04:28