代码点读机 / C / math.h

math.h C · 头文件

C 数学库的头文件,包含 sqrt、pow、sin、cos 等数学函数声明。

怎么用

#include <math.h>

小例子

#include <stdio.h>
#include <math.h>
int main(void) {
    printf("%f", sqrt(9.0));
    return 0;
}

运行结果

输出 3.000000

提醒:链接阶段通常要加 -lm 链接数学库;不是编译阶段选项

官方文档:https://en.cppreference.com/w/c/numeric/math

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← C全部词条