1.7計算球體積 HDU - 2002

題目: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來定義小數點後保留多少位
 }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章