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 != 999)
  30.  
  31. {
  32.  
  33. printf("Enter a positive Integer\n");
  34.  
  35. scanf("%d", &value);
  36. if (value != 999) {
  37. sum = sum + value;
  38. count = count + 1;
  39. {
  40. break;
  41. }
  42. }
  43. else {
  44. printf("Value must be positive\n");
  45. }
  46.  
  47. }
  48.  
  49. // Calculate avg. Need to type cast since two integers will yield an integer
  50.  
  51. avg = (double) sum/count;
  52.  
  53. printf("average is %lf\n " , avg );
  54.  
  55. return 0;
  56.  
  57. }
Success #stdin #stdout 0s 9432KB
stdin
10
20
30
40
20
stdout
Enter a positive Integer
average is 10.000000