Facebook
From 210505, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 101
  1. #include<iostream>
  2. using namespace std ;
  3. int main()
  4.  
  5. {
  6. int i, n, sum, array[100];
  7. float average;
  8.  
  9. cout<<"Enter number of elements: ";
  10. cin >> n;
  11.  
  12. cout<<"Enter " << n << " elements in array: "<<endl;
  13.  
  14. for(i = 0; i < n; i++)
  15.  {
  16. cin >> array[i];
  17. }
  18.  
  19. sum = 0;
  20.  
  21. for(i = 0; i < n; i++)
  22. {
  23. sum += array[i];
  24. }
  25.  
  26. average = (float)sum / n;
  27. cout << "Average: " << average;
  28.  
  29. return 0;
  30. }