【c语言】学习math库函数

【c】math库函数

绝对值

#include <math.h>
int main() {
	printf("%lf\n", fabs(-4.2));
	return 0;
}
//4.200000

取整

#include <math.h>
//向上取整
int main() {
	printf("%lf\n", ceil(2.6)); //ceil向上取整
	return 0;
}
//3.000000
//向下取整  小于等于当前数的最大整数 int floor(double x);
int main() {
	printf("%lf\n", floor(2.7));
	return 0;
}
//2.000000
```c
## 取模
```c
#include <math.h>
//被除数a/除数b=商...余数 ,余数就是取模结果
//整数取模:% 
//double fmod(double a,double b);
int main() {
	printf("%lf\n", fmod(15, 4.3));
	return 0;
}
//2.100000

次幂

#include <math.h>
//double pow(double a;double b); //b个a连乘,也就是a的b次
int main() {
	printf("%lf\n", pow(2, 3));
	return 0;
}
//8.000000
//计算距离,两点差的平方和开根号
int main() {
	printf("%lf\n",sqrt(9));
	return 0;
}
//3.000000

对数

#include <math.h>
//double log2(double b); log以2为底b的对数
int main() {
	printf("%lf\n", log2(16));
	return 0;
}
//4.000000

三角函数

sinx

#include <math.h>
//Π=3.1415926536
int main() {
	printf("%lf\n", sin(3.1415926536 / 6));
	return 0;
}
//0.500000   sin30度=1/2

cosx

int main() {
	printf("%lf\n", cos(3.1415926536 / 3));
	return 0;
}
//0.500000  cos60度=1/2

tanx

int main() {
	printf("%lf\n", tan(3.1415926536 / 4));
	return 0;
}//1.000000 tan45度=1

cotx math.h中没有cot函数

int main() {
	printf("%lf\n", 1/tan(3.1415926536 / 4));  //没有cot函数
	return 0;
}//1.000000

反三角函数

arcsinx

#include <math.h>
//double asin(double x); arcsinx
int main() {
	printf("%lf\n", asin(sin(1)));
	return 0;
}//1.000000

arccosx

int main() {
	printf("%lf\n", acos(cos(2)));
	return 0;
}//2.000000

arctanx

int main() {
	printf("%lf\n", atan(tan(3)));
	return 0;
}//-0.141593 

双曲函数

#include <math.h>
int main() {
	//printf("%lf\n", sinh(0));//0.000000
	//printf("%lf\n", cosh(0)); //1.000000
	printf("%lf\n", tanh(0)); //0.000000
	return 0;
}
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值