C++——半球面积

半球面积

需求如下:

 

 

代码如下:

 1 #include <iostream>
 2 #include <iomanip>  //下边用到保留小数需要包含的头文件
 3 using namespace std;
 4 int main()
 5 {
 6     double d=0.3,pi=3.14,s;
 7     s=2*pi*(d/2)*(d/2);
 8     cout<<fixed<<setprecision(5)<<s<<endl; //保留五位小数
 9     return 0;
10 }

 

分析与总结:

 1、这个题的重点就是结果要保留五位小数cout<<fixed<<setprecision(n)  n为保留小数的位数。

 

 

写在最后:

  哪里有不足或者错误的地方,欢迎小伙伴们进行指教,一起进步哦!

posted @ 2020-09-08 21:29  闫佳杰  阅读(277)  评论(0)    收藏  举报