gpt4 book ai didi

c - 如何调用函数并使用其结果?

转载 作者:行者123 更新时间:2023-11-30 19:03:32 24 4
gpt4 key购买 nike

我必须使用原型(prototype)poly float 来计算f(x)=5x^2+12.55x+0.75。每次运行此代码时都会出错,因为未使用 Poly。任何帮助都会很好,对于原型(prototype)的任何提示也是如此。

#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));

关于c - 如何调用函数并使用其结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53808498/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com