ulvis.paste.net

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