天天看點

HDU-2002 計算球體積代碼注解結果

HDU-2002 計算球體積代碼注解結果
HDU-2002 計算球體積代碼注解結果

代碼

#include <iostream>
#include <math.h>

using namespace std;

const double PI = 3.1415927;

int main() {
    double r;
    while(cin>>r) {
        double ans = 4.0*PI*r*r*r/3.0;
        printf("%.3f\n", ans);
    }
    return 0;
}
           

注解

1、球的公式。

2、保留三位小數的寫法。

3、PI的常數取值。

結果

HDU-2002 計算球體積代碼注解結果