Since your question is so unclear, I guess I'll just go over everything that's wrong:
Void Main()
This is not a valid declaration of main
, which must be declared as returning an int
.
{
float a;
b=square(a);
}
No b
variable is declared, and you're invoking square
on an uninitialized variable, so you're passing garbage to your function.
Also note that you haven't given a function prototype (a.k.a a function declaration) for your square
function. I'm guessing that this is what your compiler is complaining about; without the declaration, it will make assumptions about what your function returns and about what types of arguments it takes (assumptions that in this case will be wrong).
int square(float a )
It doesn't make sense for square
to take a floating point argument but to return an integer type. If you called square(2.5)
(and assuming your function worked), instead of returning 6.25, it would return 6.
{
int y;
y=a*a;
return(a);
}
Here you're returning the argument you were passed in (rounded toward 0 due to the conversion to int
), not the squared result, so your function doesn't actually do what it's supposed to do.