Advertisement
Guest User

AVERAGES

a guest
Sep 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /*Read a set of values from the user.Store the sum in the sum variable and return the number of values read.*/
  4. int read_values(double sum) {
  5. int values=0,
  6. input=0;
  7. sum = 0;
  8. printf("Enter input values (enter 0 to finish):\n");
  9. scanf("%d",&input);
  10. while(input != 0) {
  11. values++;
  12. sum += input;
  13. scanf("%d",input);}
  14.  
  15. return values;}
  16.  
  17. int main() {
  18. double sum=0;
  19. int values;
  20. values = read_values(sum);
  21. printf("Average: %g\n",sum/values);
  22. return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement