Advertisement
joy007

variable.c

Jul 23rd, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. /* The program demonstrates functions returning a value by passing
  2. three floating-point numbers (grades) and calculating the average of
  3. the three */
  4.  
  5. #include <stdio.h>
  6.  
  7. float gradeAve(float test1, float test2, float test3);
  8.  
  9. int main(void)
  10. {
  11. float grade1, grade2, grade3;
  12. float average;
  13.  
  14. printf("What was the grade on the first test? ");
  15. scanf(" %f", &grade1);
  16.  
  17. printf("What was the grade on the second test? ");
  18. scanf(" %f", &grade2);
  19.  
  20. printf("What was the grade on the third test? ");
  21. scanf(" %f", &grade3);
  22.  
  23. // Pass the three grades to the function and return the average
  24.  
  25. average = gradeAve(grade1, grade2, grade3);
  26. printf("\nWith those three test scores, the average is %.2f",
  27. average);
  28. return 0;
  29. }
  30.  
  31. /********************************************************************/
  32.  
  33. float gradeAve(float test1, float test2, float test3)
  34. // Receives the values of three grades
  35. {
  36. float localAverage;
  37.  
  38. localAverage = (test1+test2+test3)/3;
  39.  
  40. return (localAverage); // Returns the average to main
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement