关于输出这种输出两点之间的距离的数学函数
首先,我们需要导cmath包 ,如 #include,才能使用根号()及平方()等数学符号
#include<cstdio>
#include<cmath>
int main()
{
}
其次,在代码中运用数学符号
#include<cstdio>
#include <cmath>
using namespace std;
main()
{
double x1, y1, x2, y2;
scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
printf("%.4lf", sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)));
return 0;
}
其中,saqrt()表示对括号内开根,pow(a,b)表示,其他数学符号后期补充
还有一点,头文件可写#define PI 3.14159表示定义了常量PI 其值为3.14159,其值在整个main方法中不能改变
省略部分头文件
#define PI 3.14159
int main()
{
int r = 2;
cout <<"半径为2的圆面积为:" << PI * r * r << endl ;
}