C语言math.c的运用

1.fab(double x)
该函数用于对double型变量取绝对值
#include<stdio.h>
#include<math.h>
int main(){
double db = -12.56;
printf("%.2f", fabs(db));
return 0;
}
2.floor(double x) ceil(double x)
两个函数分别用于double类型变量的向下取整和向上取整,返回类型为double。
#include<stdio.h>
#include<math.h>
int main(){
double db1 = -5.2, db2 = 5.2;
printf("%.0f %.0f\n", floor(db1), ceil(db1));
printf("%.0f %.0f\n", floor(db2), ceil(db2));
return 0;
}
结果
-6 -5
5 6
3.pow(double r, double p)
函数返回r^p, r和p均为double型。
#include<stdio.h>
#include<math.h>
int main(){
double db = pow(2.0, 3.0);
printf("%f\n", db);
return 0;
}
输出 8.000000

4.log(double x)
这里若需要使用ln函数,则需要使用exp();
以自然对数为底数的对数
#include<stdio.h>
#include<math.h>
int main(){
double db = log(100)/log(10);
printf("%f\n0", db);
return 0;
}

输出
2.000000

6.sin(double x)、cos(double x)、tan(double)
#include<stdio.h>
#include<math.h>
const double pi = acos(-1.0);
int main(){
double db1 = sin(pi * 45 / 180);
double db2 = cos(pi * 45 / 180);
double db3 = tan(pi * 45 / 180);
printf("%f, %f, %f\n", db1, db2, db3);
return 0;
}
输出
0.707107, 0.707107, 1.000000

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值