NYOJ:计算球体积

C语言代码:

#include<stdio.h>
#define PI 3.1415926
int main()
{
    double r,s;
    while(~scanf("%lf",&r))
    {
    s=PI*r*r*r*4/3;
    printf("%.0lf\n",s);
    }
    return 0;

}

C++代码:

#include<iostream>
using namespace std;
#define PI 3.1415926
int main()
{
    double r;
    while(cin>>r)
    {
        int s=4.0/3.0*PI*r*r*r+0.5;      //四舍五入要先加上0.5,再将变量定义为int型输出
        cout<<s<<endl;
    }
    return 0;
}


相关文章:

  • 2021-10-28
  • 2022-01-27
  • 2021-12-24
  • 2021-11-30
  • 2022-01-05
  • 2022-01-21
猜你喜欢
  • 2021-05-08
  • 2021-08-17
  • 2021-06-24
  • 2022-02-13
  • 2021-06-12
相关资源
相似解决方案