Ned help with mean()

Hi guys.I need help with C programming. Im sorry that its not C++ but I hope Im welcome to ask still.

How do I declare the function "mean()"?
And how do I define it?

This is my homework. How do I proceed?




/* Declaration of mean() before main */

int main( )
{
double result;
result = mean( 1.0, 3.0 );
printf("%.f\n", result); /* Should give 2.000000 */
return 0;
}

/* Definition of mean() after main */
Declaring a function means writing its prototype.
Defining a function means writing its code.
Ok. Ive come this far.
But I still dont know how to define it. Do you mean I should move the code to that is in between the brackets to after main? Can you copy and paste and show me how to do that?


#include <stdio.h>


float mean (float x, float y)
{
float result;

result = (x+y)/2;

return result;
}

int main( )
{
double result;
result = mean( 1.0, 3.0 );
printf("%f\n", result);
getchar();
return 0;
}

/* Definition of mean() after main */
Ok I think Ive solved it. But thx for help.
Topic archived. No new replies allowed.