fork download
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <iostream>
  5. #include <vector>
  6.  
  7. using namespace std;
  8. int main()
  9. {
  10. srand(time(0));
  11.  
  12. //Random number from 3 to 7
  13. int numberOfVectors = (rand() % 4) + 3;
  14.  
  15. //Random number from 5 to 10.
  16. int size = (rand() % 5) + 5;
  17.  
  18. std::cout << "There are " << numberOfVectors << " vectors." << std::endl;
  19. std::cout << "Each vector has " << size << " elements." << std::endl;
  20.  
  21. std::vector< std::vector<int> > vectorOfVectorOfInt;
  22.  
  23. std::cout << "Value per element: 0 = Not available, 1 = available" << std::endl;
  24.  
  25. for(int vec = 0; vec < numberOfVectors; vec++)
  26. {
  27. //Create a new vector with 'size' elements.
  28. std::vector<int> newVector(size);
  29.  
  30. for(int i = 0; i < size; i++)
  31. {
  32. //Generate a random value between 0 and 50
  33. newVector[i] = (rand() % 50);
  34. }
  35.  
  36. //Add the vector to our vector-of-vectors.
  37. vectorOfVectorOfInt.push_back(newVector);
  38.  
  39. std::cout << "The values for Vector #" << (vec+1) << " is:";
  40. for(int b = 0; b < size; b++)
  41. {
  42. int value = vectorOfVectorOfInt[vec][b];
  43. std::cout << "\t" << value;
  44. }
  45. std::cout << std::endl;
  46. }
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
There are 6 vectors.
Each vector has 6 elements.
Value per element: 0 = Not available, 1 = available
The values for Vector #1 is:	41	22	23	5	2	36
The values for Vector #2 is:	23	19	0	25	25	35
The values for Vector #3 is:	16	7	19	39	19	2
The values for Vector #4 is:	7	33	32	44	46	30
The values for Vector #5 is:	36	37	47	18	38	4
The values for Vector #6 is:	31	30	27	4	35	29