我是新手,请问怎样取整数,去掉小数点后面的数。谢谢!
写一个程序,读入一个球体的半径,计算出它的表面积和体积,然后打印他们向下调整至最接近的整数。
定义一个常数,称为PI,并给它值3.14公式中使用的:
示例输出
半径为5
的表面积是:314
体积为:523
#include <iostream>
using namespace std;
int main()
{
double radius;
double surfaceArea;
int volume;
double PI;
double a;
double b;
cout << "Program to compute and output the volume and surface area of a sphere" << endl;
cout <<"Input radius:"<< endl;
cin >> radius;
PI = 3.14;
a=4;
b=3;
surfaceArea=4* PI * radius * radius;
volume = a / b * PI * radius * radius *radius;
cout << "Radius is: " << radius << endl;
cout << "The surface area is:" << surfaceArea << endl;
cout << "The volume is: " << volume << endl;
return 0;
}