温馨提示×

C语言怎么引入math库

小亿
117
2024-05-14 17:14:14
栏目: 编程语言

要在C语言中引入math库,需要在代码中包含以下语句:

#include <math.h>

这样就可以使用math库中定义的数学函数了。例如,可以使用sqrt函数来计算一个数的平方根:

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

int main() {
    double num = 16.0;
    double result = sqrt(num);
    
    printf("The square root of %f is %f\n", num, result);
    
    return 0;
}

0