海伦公式了解
举例
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(void)
{
float a=0,b=0,c=0;
cin>>a>>b>>c;
float p=(a+b+c)/2;
cout<<fixed<<setprecision(2)<<"circumference="<<a+b+c<<" area="<<sqrt(p*(p-a)*(p-b)*(p-c));
}
单纯会用学会sqrt(n) n可为数字也可为字母a,仅学到这就可以了
关于如何控制小数输出位数在我这篇文章有讲解
https://blog.csdn.net/lpblog/article/details/105886550
说明
sqrt函数
- 头文件加入
#include<cmath>
- 函数原型为
double sqrt(double);
//function prototype
上述例子因函数原型略不规范数据类型应为double - sqrt( )是一个使用又返回值的函数
double sqrt(double);//第一个double sqrt函数将返回一个double值,括号中的double意味需要一个参数
举例
double x;
x=sqrt(6.25);
#include<iostream>
#include<cmath>
using namespace std;
int main(void)
{
double a=9,b=9;
cout<<sqrt(9)<<endl;
cout<<sqrt(a)<<endl;
double c=sqrt(b);
cout<<c<<endl;
}
3
3
3
pow函数
函数原型
double pow(double,double);
answer=pow(2.0,8.0)//计算2的8次方
#include<iostream>
#include<cmath>
using namespace std;
int main(void)
{
double a=2.0,b=8.0;
double answer=pow(2.0,8.0);
cout<<answer<<endl;
}
256