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