題目:https://vjudge.net/problem/hdu-2002
思路:循環用公式求出每一個球的體積。
c++ AC代碼如下:
#include <iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
double r, V;
const double pi = 3.1415927;
while (cin >> r)
{
V = 4.0 / 3.0*pi*pow(r, 3); //避免4/3=1
cout <<fixed<<setprecision(3)<< V << endl; //直接用fixed來定義小數點後保留多少位
}
}