log10() 函数在 math.h 头文件中定义。它有助于返回给定参数值的以 10 为底的对数。
double log10(double x); #where x should be in double
此外,还使用了 log10f() 和 log10l() 两个函数,分别对应 float 和 long double 类型。
float log10f(float x);
long double log10l(long double x);
log10() 函数接受一个 double 类型的参数。
| 参数 | 描述 | 必需/可选 |
|---|---|---|
| x | 需要查找其以 10 为底的对数 | 必需 |
log() 函数的返回值为浮点数。
| 输入 | 返回值 |
|---|---|
| x > 0 | 查找参数的 log10 |
| x < 0 | 显示运行时错误 |
#include <stdio.h>
#include <math.h>
int main()
{
double N = 4.00, output;
output = log10(N);
printf("The value of log10(%.1f) is %.2f", N, output);
return 0;
}
输出
The value of log10(4.0) is 0.60
#include <stdio.h>
#include <math.h>
int main () {
double k, out;
k = 10000;
out = log10(k);
printf("The value of log10(%lf) is %lf", k, out);
return(0);
}
输出
The value of log10(10000.000000) = 4.000000