C examples for Function:Function Parameter
Returning a value by passing three floating-point numbers and calculating the average.
#include <stdio.h> float gradeAve(float test1, float test2, float test3); int main()/*from w w w . j a v a2 s. c o m*/ { float grade1, grade2, grade3; float average; printf("What was the grade on the first test? "); scanf(" %f", &grade1); printf("What was the grade on the second test? "); scanf(" %f", &grade2); printf("What was the grade on the third test? "); scanf(" %f", &grade3); //Pass the three grades to the function and return the average average = gradeAve(grade1, grade2, grade3); printf("\nWith those three test scores, the average is %.2f", average); return 0; } float gradeAve(float test1, float test2, float test3){ float localAverage; localAverage = (test1+test2+test3)/3; return (localAverage); // Returns the average to main }