如何调用函数并使用其结果?
How do I call a function and use its result?
我必须使用原型 poly float 来计算 f(x)=5x^2+12.55x+0.75
。我每次 运行 这段代码都会出错,因为没有使用 poly。任何帮助都是好的,任何关于原型的提示也是如此。
#include<stdio.h>
float poly(float x)
{
return 1;
}
int main()
{
float b, c, a;
printf("Podaj x=");
a = scanf("%f", &b);
c = 5 * b * b + 12.55 * b + 0.75;
if(a<1)
{
printf("Incorrect input");
return 1;
}else
{
printf("Wynik: %.2f", c);
return 0;
}
}
将poly
更改为:
float poly(float x)
{
return 5*x*x + 12.55*x + .75;
}
在main中,可以使用函数:
print("poly(%g) = %g.\n", b, poly(b));
我必须使用原型 poly float 来计算 f(x)=5x^2+12.55x+0.75
。我每次 运行 这段代码都会出错,因为没有使用 poly。任何帮助都是好的,任何关于原型的提示也是如此。
#include<stdio.h>
float poly(float x)
{
return 1;
}
int main()
{
float b, c, a;
printf("Podaj x=");
a = scanf("%f", &b);
c = 5 * b * b + 12.55 * b + 0.75;
if(a<1)
{
printf("Incorrect input");
return 1;
}else
{
printf("Wynik: %.2f", c);
return 0;
}
}
将poly
更改为:
float poly(float x)
{
return 5*x*x + 12.55*x + .75;
}
在main中,可以使用函数:
print("poly(%g) = %g.\n", b, poly(b));