fork download
  1. #include <iostream>
  2. #include <functional>
  3. #include <numeric>
  4. #include <vector>
  5. using namespace std;
  6.  
  7.  
  8. int main(){
  9.  
  10. const int n = 10; /* number of the elements (>0) */
  11. vector<int> vv;
  12. int tmp;
  13. for(int i=0;i<n;i++)
  14. {
  15. cin>>tmp;
  16. vv.push_back(tmp); /* one way to insert the element to the last position in the vector */
  17. }
  18. double mean = accumulate(vv.begin(), vv.end(), 0.0) / vv.size(); /* or you can write /n */
  19. cout<<"Required mean = "<< mean <<endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 2820KB
stdin
1
2
3
4
5
6
7
8
9
10
stdout
Required mean = 5.5