ACM第一期練習題第七小題:計算球體積
阿新 • • 發佈:2018-12-14
click here to have a try
問題要求:
Time limit 1000ms
Memory 32768KB
問題資料:
根據輸入的半徑值,計算球的體積。
Input
輸入資料有多組,每組佔一行,每行包括一個實數,表示球的半徑。
Output
輸出對應的球的體積,對於每組輸入資料,輸出一行,計算結果保留三位小數。
Sample Input
1
1.5
Sample Output
4.189
14.137
問題簡述:
第一行輸入半徑,第二行輸出結果,要能夠輸入多組資料進行計算,且要結果保留三位小數。
問題分析:
利用while()來實現輸入多組資料,輸入輸出的資料應為double型別。
Virtual Judge通過的程式碼如下:
#include <iostream>
#include <cstdio>
#define pi 3.1415927
using namespace std;
int main()
{
double r;
while (cin >> r)
{
double v;
v = 4.0 / 3 * pi*r*r*r;
printf("%.3lf\n",v );
}
return 0;
}