fork download
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int n, values, count=0,Sum=0;
  6. double Average;
  7.  
  8. printf("\nPlease Enter how many values you want to input?\n");
  9. scanf("%d",&n);
  10. printf("Number of the values = %d",n, count);
  11. printf("\nPlease Enter the values one by one\n");
  12. while(count<n)
  13. {printf("Enter a positive Integer\n");
  14. scanf("%d", &values); if (values >= 0)
  15. { Sum = Sum + values; count = count + 1; }
  16. else { printf("Value must be positive\n"); }
  17. scanf("%d",&values);
  18. Sum = Sum +values;
  19. count++;
  20. }
  21.  
  22. Average = (double) Sum/n;
  23.  
  24. printf("\nSum of the %d Numbers = %d",n, Sum);
  25. printf("\nAverage of the %d Numbers = %.2f",n, Average);
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 15232KB
stdin
3

10.9
11.1
23.0
stdout
Please Enter how many values you want to input?
Number of the values = 3
Please Enter the values one by one
Enter a positive Integer
Enter a positive Integer

Sum of the 3 Numbers = 40
Average of the 3 Numbers = 13.33