2.设圆半径r=1.5,圆柱高h=3,求圆周长、圆面积、圆球表面积、圆球体积、圆柱体积。用cin输入数据,输出计算结果,输出是要求有文字寿命,取小数点后两位数字。
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main() {
float r, h, l, s, sq, vq, vz;
const float pi = 3.1415926;
cout << "Please enter r,h:";
cin >> r >> h;
l = 2 * r * pi;
s = pi * r * r;
sq = 4 * pi * r * r;
vq = 3.0 / 4.0 * pi * r * r * r;
vz = pi * r * r * h;
cout << setiosflags(ios::fixed) << setiosflags(ios::right) << setprecision(2);//设置输出格式
cout << "l=" << setw(10) << l << endl; //指定字段宽度为10
cout << "s=" << setw(10) << s << endl;
cout << "sq=" << setw(10) << sq << endl;
cout << "vq=" << setw(10) << vq << endl;
cout << "vz=" << setw(10) << vz << endl;
return 0;
}
输出结果:
3.输入一个华氏温度,要求输出摄氏温度。公式为c=5/9(F-32),输出要有文字说明,取两位小数。
#include<iostream>
#include<iomanip>
using namespace std;
int main() {
float c, f;
cout << "请输入一个华氏温度:";
cin >> f;
c = (5.0 / 9.0) * (f - 32);
cout << setiosflags(ios::fixed) << setprecision(2) << "摄氏温度为:" << c << e