赞
踩
函数解释见代码注释:
#include<stdio.h> #include<math.h> 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; }
结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。