圆的面积

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 int main(int argc, char** argv) {
 6     double  r=1.0;
 7     cout<<"r="<<r<<endl;
 8     double l;
 9     l=2*3.1416*r;           //计算圆的周长,赋值给变量l
10     cout<<"l="<<l<<endl;    //显示圆的周长    
11     double s=3.1416*r*r;     //计算圆的面积,赋值给变量s 
12     cout<<"s="<<s<<endl;    //显示圆的面积
13 
14     cout<<"R=";            //显示提示输入的信息
15     cin>>r;                 //键盘输入
16     l=2*3.1416*r;           //计算圆的周长,赋值给变量l
17     cout<<"l="<<l<<endl;    //显示圆的周长
18     s=3.1416*r*r; 
19     cout<<"s="<<s<<endl;    //显示圆的面积
20     return 0;
21 }

 

posted @ 2018-08-02 10:28  borter  阅读(112)  评论(0编辑  收藏  举报