fork download
  1. // C code
  2. // This program will calculate the sum of 10 positive integers.
  3. // Developer: CARLOS CMIS102
  4. // Date: SEPTEMBER 18, 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 <-20)
  17. {
  18. printf("Enter negative Integer\n");
  19. scanf("%d", &value);
  20. if (value >= 0)
  21. {
  22. sum = sum - value;
  23. count = count + 1;
  24. }
  25. else {
  26. printf("Value must be negative\n");
  27. }
  28. }
  29. // Calculate avg. Need to type cast since two integers will yield an integer
  30. avg = (double) sum/count;
  31. printf("average is %lf\n " , avg );
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 9424KB
stdin
-2
-4
-7
-9
-3
-1
-8
-10
-12
-18
-0
-5
-4
-7
-2
-1
-6
-13
-11
-19
-16
stdout
average is -nan