c++求面积问题

来源:百度知道 编辑:UC知道 时间:2024/06/20 17:10:25
先要define a 4.828
计算圆面积
要使用POW
要求输入 半径
然后用S=b*pow(r,2)
求出答案

#include<iostream.h>
#include<math.h>
const double PI =3.1415926535;
int main()
{
double r,s;
cout<<"Input the radi"<<endl;
cin>>r;
s=PI*pow(r,2);
cout<<"the square is "<<endl<<s;
return 0;
}

#include<stdio.h>
#include<math.h> //包含pow函数的头文件
const double PI =3.1415926535; //如果求圆的面积应该是圆周率而不是4.828,建议不要使用define

int main()
{
double r,s;
printf("Input the radii:");
scanf("%lf",&r);
s=PI*pow(r,2);
printf("the square is %lf\n",s);
return 0;
}