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