Mega Code Archive

 
Categories / C / Code Snippets
 

Definition of the function to calculate an average

#include <stdio.h> float average(float j, float k) { return (j + k)/2.0f; } /* main program - execution always starts here */ void main() { float average(float j, float k); /* Function prototype */ float value1 = 1.0F; float value2 = 2.0F; float r = 0.0F; r = average(value1, value2); printf("\nThe average is: %f", r); }