fork download
  1. #include <stdio.h>
  2.  
  3. int main ()
  4.  
  5. {
  6.  
  7. /* variable definition: */
  8.  
  9. int input,count, value, sum;
  10. double avg;
  11.  
  12. /* Initialize */
  13.  
  14. count = 0;
  15.  
  16. sum = 0;
  17. avg = 0.0;
  18.  
  19. // Enter the amount of numbers to calculate the average
  20.  
  21.  
  22. // Loop through to input values
  23. printf("Enter the total amount of numbers you will enter \n");
  24. scanf("%d", input);
  25. while (count < input)
  26.  
  27.  
  28. {
  29.  
  30. printf("Enter a positive Integer\n");
  31.  
  32. scanf("%d", &value);
  33. if (value >= 0) {
  34. sum = sum + value;
  35. count = count + 1;
  36. }
  37. else {
  38. printf("Value must be positive\n");
  39. }
  40.  
  41. }
  42.  
  43. // Calculate avg. Need to type cast since two integers will yield an integer
  44.  
  45. avg = (double) sum/count;
  46.  
  47. printf("average is %lf\n " , avg );
  48.  
  49. return 0;
  50.  
  51. }
Runtime error #stdin #stdout 0s 4276KB
stdin
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
stdout
Standard output is empty