ulvis.paste.net

Paste Search Dynamic
Recent pastes
will calculate the sum of 10
  1. // C code
  2. // This program will calculate the sum of 10 positive integers.
  3. // Developer: Faculty CMIS102
  4. // Date: Feb 11, 2018
  5. #include <stdio.h>
  6. int main ()
  7. {
  8. /* variable definition: */
  9. int count, value, sum;
  10. double avg;
  11. /* Initialize */
  12. count = 0;
  13. sum = 0;
  14. avg = 0.0;
  15. // Loop through to input values
  16. while (count < 10)
  17. {
  18.  printf("Enter a positive Integer\n");
  19.  scanf("%d", &value);
  20.  if (value >= 0) {
  21.  sum = sum + value;
  22.  count = count + 1;
  23.  }
  24.  else {
  25.  printf("Value must be positive\n");
  26.  }
  27. }
  28. // Calculate avg. Need to type cast since two integers will yield an integer
  29. avg = (double) sum/count;
  30. printf("average is %lf\n " , avg );
  31. return 0;
  32. }
  33.  
Parsed in 0.003 seconds