fork(1) download
  1. // C code
  2.  
  3. //
  4.  
  5. // Developer: Anthony Legaspi
  6.  
  7. // Date: June 23,2018
  8.  
  9. #include <stdio.h>
  10.  
  11. int main ()
  12.  
  13. {
  14.  
  15. /* variable definition: */
  16.  
  17. int count, value, sum, userInput;
  18. double avg;
  19.  
  20.  
  21. count = 0;
  22. sum = 0;
  23. avg = 0.0;
  24.  
  25. printf("How many you wanna do?:\n");
  26.  
  27. scanf("%i", &userInput);
  28.  
  29. while (count < userInput)
  30.  
  31.  
  32.  
  33. {
  34.  
  35. printf("Enter a positive Integer\n");
  36.  
  37. scanf("%d", &value);
  38. if (value >= 0) {
  39. sum = sum + value;
  40. count = count + 1;
  41. }
  42. else {
  43. printf("Value must be positive\n");
  44. }
  45.  
  46. }
  47.  
  48. // Calculate avg. Need to type cast since two integers will yield an integer
  49.  
  50. avg = (double) sum/count;
  51.  
  52. printf("average is %lf\n " , avg );
  53.  
  54. return 0;
  55.  
  56. }
Success #stdin #stdout 0s 4328KB
stdin
3
1
2
2
3
3
stdout
How many you wanna do?:
Enter a positive Integer
Enter a positive Integer
Enter a positive Integer
average is 1.666667