fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. void fRandomArrayFill(vector <int> vec);
  9.  
  10.  
  11. int main()
  12. {
  13. srand(time(0));
  14. vector <int> x;
  15. int size;
  16. cout<<"Enter the size of vector: ";
  17. cin>>size;
  18. x.resize(size);
  19. cout<<"Creating and filling array with random numbers..."<<endl;
  20. fRandomArrayFill(x);
  21. cout<<"{";
  22. for (int i=0;i<x.size();i++)
  23. cout<<x[i]<<" ";
  24. cout<<"}"<<endl;
  25. vector <int> y=x;
  26. cout<<endl<<y[3];
  27. cout<<"Press any key to continue...";
  28. cin.get();
  29. cin.get();
  30. return 0;
  31. }
  32.  
  33. void fRandomArrayFill (vector <int> vec)
  34. {
  35. for (int i=0;i<vec.size();i++)
  36. vec[i]=rand() %101;
  37. }
Success #stdin #stdout 0s 3436KB
stdin
5
stdout
Enter the size of vector: Creating and filling array with random numbers...
{0 0 0 0 0 }

0Press any key to continue...