如下代码:
#include <stdio.h> // 调用基本输入输出函数库
#include <math.h>
#define PI 3.14 // 定义常量
float area(float r) // 定义
{
float s;
s = PI * pow(r, 2);
return s;
}
int main()
{
float r, s;
printf("半径 = ");
scanf("%f", &r);
s = area(4);
printf("
面积 = %f
", s);
return 0;
}
编译时,报错:
对‘pow’未定义的引用
解决方案:
编译时,需要链接数学库,参考代码如下:
gcc area.c -o area.out -lm
参考: