[英]C basic - called object is not a function or function pointer
That's my code - 那是我的代码-
main()
{
double x;
double y = pow(((1/3 + sin(x/2))(pow(x, 3) + 3)), 1/3);
printf("%f", y);
return 0;
}
I get an error in double y = pow((1/3 + sin(x/2))(pow(x, 3) + 3), 1/3);
我在
double y = pow((1/3 + sin(x/2))(pow(x, 3) + 3), 1/3);
, it says that called object is not a function or function pointer. ,它表示被调用的对象不是函数或函数指针。 I don't get it though -
(1/3 + sin(x/2))(pow(x, 3) + 3)
is the first element of pow(x, y);
我不明白-
(1/3 + sin(x/2))(pow(x, 3) + 3)
是pow(x, y);
的第一个元素pow(x, y);
that is the x I want to raise to y (1/3) power. 那就是我想提高到y(1/3)幂的x。 Where lies the problem?
问题出在哪里? I'm pretty new to c basic but I can't find the answer anywhere.
我对C Basic还是很陌生,但在任何地方都找不到答案。
That's because the return value of pow
is a double, not a function. 这是因为
pow
的返回值是双pow
值,而不是函数。 Maybe what you're trying to do is pass a call to pow
as the second argument to the first pow. 也许您想要做的是将对
pow
的调用作为第一个pow
的第二个参数传递。
If you want to multiply, you need to use the *
operator. 如果要相乘,则需要使用
*
运算符。 You can't put parenthesized expressions adjacent to each other to denote multiplication. 您不能将带括号的表达式彼此相邻以表示乘法。
(1/3 + sin(x/2))*(pow(x, 3) + 3)
#include <stdio.h>
#include <math.h> // For pow() function
int main() {
// Initialize with whatever value you want
double x = 100;
// Make sure to use an arithmetic operator
double y = pow(((1/3.0 + sin(x/2))*(pow(x, 3) + 3)), 1/3.0);
// Use right format specifier
printf("%lf", y);
return 0;
}
math.h
library. math.h
库。 x
with a value. x
。 1/3
, instead use 1/3.0
or 1.0/3.0
because 1/3 == 0
. 1/3
,而使用1/3.0
或1.0/3.0
因为1/3 == 0
。 +
, -
, *
, /
) before middle pow()
like pow(((1/3.0 + sin(x/2))+(pow(x, 3) + 3)), 1/3.0)
. pow(((1/3.0 + sin(x/2))+(pow(x, 3) + 3)), 1/3.0)
中间pow()
)之前使用算术运算符( +
, -
, *
, /
) pow(((1/3.0 + sin(x/2))+(pow(x, 3) + 3)), 1/3.0)
。 y
which is %lf
. y
使用正确的格式说明符%lf
。 But you may get away with %f
. %f
脱身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.