#include <iostream>
//#include <math.h>
#include <cmath>//平方 pow(4,2) 开方sqrt(4) 绝对值abs(1-9)
using namespace std;
int main()
{
//平方 pow()
int a = pow(4,2);// 4的平方=16
//开方
int b = pow(4,0.5);// 4的平方根=2
int c = sqrt(4);// 4的平方根=2
//整数绝对值
int d = abs(1-8);
//浮点数绝对值
double e = fabs(3.0-5.8);
cout<<"4的平方是"<<a<<endl;
cout<<"4的平方根是"<<b<<endl;
cout<<"4的平方根是"<<c<<endl;
cout<<"1-8的整数绝对值是"<<d<<endl;
cout<<"3.0-5.8浮点数绝对值是"<<e<<endl;
return 0;
}
C++中的平方、开方、绝对值
最新推荐文章于 2024-03-22 22:07:48 发布