Error: 'Math' undeclared first use in this function
Error: 'Math' undeclared first use in this function
我不断收到此错误:
'Math' undeclared first use in this function
尽管我包含了数学库。
int x = Math.pow(10.0,(double)k);
这是我收到错误的行,知道为什么吗?
pow
是数学库的一部分,但 C 中没有命名空间或包。
那么先
#include <math.h>
然后调用为:
int x = pow(10.0,k);
旧版本的 gcc
要求您在链接时添加 -lm
,尽管这对于最新版本是不必要的(版本 6 不再需要它)。
请注意,无需将 k
转换为 double
,而且,将结果存储在 int
(截断)
另请注意,如果您这样做是为了获得 10
的整数次幂,您最好在循环中使用整数乘法(有更好的算法,但仍然是整数,例如 The most efficient way to implement an integer based power function pow(int, int))
首先你需要在 main like
之前包含 math library
#include <math.h>
然后只需将您的代码用作
int x= pow(10.0,(double)k);
我不断收到此错误:
'Math' undeclared first use in this function
尽管我包含了数学库。
int x = Math.pow(10.0,(double)k);
这是我收到错误的行,知道为什么吗?
pow
是数学库的一部分,但 C 中没有命名空间或包。
那么先
#include <math.h>
然后调用为:
int x = pow(10.0,k);
旧版本的 gcc
要求您在链接时添加 -lm
,尽管这对于最新版本是不必要的(版本 6 不再需要它)。
请注意,无需将 k
转换为 double
,而且,将结果存储在 int
(截断)
另请注意,如果您这样做是为了获得 10
的整数次幂,您最好在循环中使用整数乘法(有更好的算法,但仍然是整数,例如 The most efficient way to implement an integer based power function pow(int, int))
首先你需要在 main like
之前包含 math library#include <math.h>
然后只需将您的代码用作
int x= pow(10.0,(double)k);