# include "iostream"using namespace std;void main(){ const int pi = 3.1415926; double r, h, v; int n; cout << "输入半径,深度" << endl; cin >> r >> h; v = pi*r*r*h; n = 20000 / v; cout << n << endl;}
3 回答
已采纳
慕田峪3750655
TA贡献1条经验 获得超1个赞
#include <iostream> using namespace std; void main() { const double pi = 3.1415926; double r, h, v; double n; cout << "输入半径,深度: " << endl; cin >> r >> h; v = pi*r*r*h; n = 20000 / v; cout << n << endl; }
头文件iostream要用<>,pi是浮点数,要用double类型。因为v是浮点数,所以所得n的值也是浮点数,也要用double类型。用int会丢失数据
- 3 回答
- 0 关注
- 1429 浏览
添加回答
举报
0/150
提交
取消