第二周-4:计算球的体积

4:计算球的体积

总时间限制: 

1000ms

内存限制: 

65536kB

描述

对于半径为r的球,其体积的计算公式为V=4/3*πr3,这里取π= 3.14。

现给定r,求V。

输入

输入为一个不超过100的非负实数,即球半径,类型为double。

输出

输出一个实数,即球的体积,保留到小数点后2位。

样例输入

4

样例输出

267.95
#include <iostream>
using namespace std;

int main()
{
	double r;
	scanf("%lf", &r);
	printf("%0.2lf", 4*3.14*r*r*r/3);
	return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
度与高度 #### 输出格式 输出两个水箱相加后的体积、面积与周长,每个结果占一行,保留小数。 ### 输入样例 ``` 2 3 4 5 6 7 ``` ### 输出样例 ``` The sum of the two boxes is: 92.00 The sum of the two boxes' surface area is: 94.00 The sum of the two boxes' perimeter is: 112.00 ``` ### 代码示例 ```cpp #include<iostream> #include<iomanip> using namespace std; class Box { public: double length, width, height; Box() {} Box(double l, double w, double h) { length = l; width = w; height = h; } Box operator+(const Box& b) { return Box(length + b.length, width + b.width, height + b.height); } Box& operator=(const Box& b) { length = b.length; width = b.width; height = b.height; return *this; } double getVolume() { return length * width * height; } }; class Rectangle : public Box { public: double getArea() { return length * width; } double getPerimeter() { return 2 * (length + width); } }; int main() { double l1, w1, h1, l2, w2, h2; cin >> l1 >> w1 >> h1 >> l2 >> w2 >> h2; Box b1(l1, w1, h1), b2(l2, w2, h2); Box b3 = b1 + b2; cout << fixed << setprecision(2); cout << "The sum of the two boxes is: " << b3.getVolume() << endl; Rectangle r1; r1.length = b1.length; r1.width = b1.width; Rectangle r2; r2.length = b2.length; r2.width = b2.width; double area = r1.getArea() + r2.getArea(); double perimeter = r1.getPerimeter() + r2.getPerimeter(); cout << "The sum of the two boxes' surface area is: " << area << endl; cout << "The sum of the two boxes' perimeter is: " << perimeter << endl; return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值