C 标准库 - <math.h>

C 语言 log10() 函数用于计算一个数的常用对数(以 10 为底)。

原型

double log10(double arg);

参数必须为正数。

示例

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

int main() {
    printf("log10(1000) = %.1f\n", log10(1000));
    return 0;
}

输出:

log10(1000) = 3.0

注意事项

使用 math.h 的函数时,多数编译器需要链接数学库(编译选项 -lm,如 gcc test.c -lm -o test)。所有三角函数使用弧度制。