【C】log()函数与pow()函数使用

 声明使用:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

 

C库函数——log()

对数函数log()


double log(double x) 返回 x 的自然对数(基数为 e 的对数)。

log==ln(其中e为底数)

 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char *argv[]) {
	double n;
	scanf("%lf",&n);//2.7
	double x = log(n);
	printf("%lf",x);//0.993252
	return 0;
}

公式:y=logz(x)

其中y是值,z是底数,x是指数

修改z的值则可以实现对数计算。

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char *argv[]) {
	double n;
	scanf("%lf",&n);//1024
	double x = log2(n);
	printf("%lf",x);//10.000000
	return 0;
}

 C库函数——pow()

 pow() 函数的声明。

double pow(double x, double y)//返回 x 的 y 次幂,即 x^y。

参数

  • x -- 代表基数的浮点值。
  • y -- 代表指数的浮点值。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char *argv[]) {

	printf("%lf\n",pow(2.0, 10));
	printf("%lf",pow(3.1, 2.1));
	
	return 0;
}

结果:

2.0^10=1024.000000

3.1^2.1=10.761172

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值