C++常用math函数

函数解释见代码注释:

#include
#include
int main() {
	double a = -12.6;
	double b = 2.0, c = 3.0;
	const double pi = acos(-1.0);//cos(-1.0)=pi,所以用反余弦acos(-1.0)取pi的值
	printf("%.1f\n", fabs(a));//绝对值
	printf("%.0f %.0f\n", floor(a), ceil(a));//向上向下取整
	printf("%f\n", pow(b, c));//b的c次方
	printf("%f\n", sqrt(b));//开平方
	printf("%f\n", log(1.0));//e为底取对数
	printf("%d\n", int(round(a)));//四舍五入
	double db1 = sin(pi * 45 / 180);//正弦,sin四十五度=二分之根号二
	double db2 = cos(pi * 45 / 180);//余弦
	double db3 = tan(pi * 45 / 180);//正切,1
	printf("%f,%f,%f\n",db1,db2,db3);
	double db4 = asin(1);//反正弦,pi/2
	double db5 = acos(-1);//反余弦,pi
	double db6 = atan(0);//反正切,0
	printf("%f,%f,%f\n", db4, db5, db6);
	return 0;
}

结果:
C++常用math函数_第1张图片

你可能感兴趣的:(菜鸡XYP的C++,c++)