C 库 - log10() 函数



C 库的 log10() 函数,类型为 double,接受参数 (x),返回x的常用对数(以 10 为底的对数)。

语法

以下是 C 库函数 log10() 的语法 -

double log10(double x)

参数

此函数仅接受一个参数 -

  • x - 这是浮点值。

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

返回值

此函数返回 x 的常用对数,其中 x 的值大于零。

示例 1

以下 C 库程序说明了 log10() 函数的用法。

Open Compiler
#include <stdio.h> #include <math.h> int main () { double x, ret; x = 10000; /* finding value of log1010000 */ ret = log10(x); printf("log10(%lf) = %lf\n", x, ret); return(0); }

输出

执行上述代码后,我们得到以下结果 -

log10(10000.000000) = 4.000000

示例 2

要计算两个对数(以 10 为底)的和,我们可以使用以下公式 -

log10​(a) + log10​(b) = log10​(a.b)

这里,公式在 C 程序中实现。

Open Compiler
#include <stdio.h> #include <math.h> int main() { // The given positive integers double a = 22.0; double b = 56.0; double sum_of_logs = log10(a * b); printf("Log10(%lf) + Log10(%lf) = Log10(%.6lf) = %.6lf\n", a, b, a * b, sum_of_logs); return 0; }

输出

执行代码后,我们得到以下结果 -

Log10(22.000000) + Log10(56.000000) = Log10(1232.000000) = 3.090611
广告