create random vectors c++

To create random vectors in C++, you can follow these steps:

  1. Include necessary libraries:
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
  1. Set the seed for the random number generator:
srand(static_cast<unsigned int>(time(0)));
  1. Define the size of the vector:
int size = 10; // for example
  1. Create the vector and populate it with random values:
std::vector<int> randomVector;
for (int i = 0; i < size; ++i) {
    randomVector.push_back(rand() % 100); // for example, generating random numbers between 0 and 99
}
  1. Display the random vector:
for (int i = 0; i < size; ++i) {
    std::cout << randomVector[i] << " ";
}

These steps will allow you to create a random vector in C++ and display its contents.