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. main()
  7. {
  8. int x,count,value,sum,inpn;
  9. double avg;
  10. // initialization
  11. for(x=1; x<=20; ++x)
  12. // Ask user 20 times
  13. {
  14. printf("Enter #%d: ",x);
  15. scanf("%d",&inpn);
  16. sum = sum + inpn;
  17. // Accumulate the next value
  18. }
  19. printf("Total Sum of 20 numbers = %d\n",sum);
  20. // Loop through to input values
  21. if (value >= 0) {
  22. sum = sum + value;
  23. count = count + 1;
  24.  
  25. }
  26. // Calculate avg. Need to type cast since two integers will yield an integer
  27. avg = (double) sum/count;
  28. printf("average is %lf\n " , avg );
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Enter #1: Enter #2: Enter #3: Enter #4: Enter #5: Enter #6: Enter #7: Enter #8: Enter #9: Enter #10: Enter #11: Enter #12: Enter #13: Enter #14: Enter #15: Enter #16: Enter #17: Enter #18: Enter #19: Enter #20: Total Sum of 20 numbers = 1219868608
average is 1219868608.000000