Definition of the function to calculate an average
#include <stdio.h>
float average(float x, float y) {
return (x + y)/2.0f;
}
/* main program - execution always starts here */
void main() {
float average(float x, float y); /* Function prototype */
float value1 = 1.0F;
float value2 = 2.0F;
float r = 0.0F;
r = average(value1, value2);
printf("\nThe average is: %f", r);
}
Related examples in the same category