Search code examples
cprototype

How do I call a function and use its result?


I have to use prototype poly float to compute f(x)=5x^2+12.55x+0.75. I have error every time I run this code because poly is not used. Any help will be good and any tips for prototypes too.

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

Solution

  • Change poly to:

    float poly(float x)
    {
        return 5*x*x + 12.55*x + .75;
    }
    

    In main, you can use the function:

    print("poly(%g) = %g.\n", b, poly(b));