C++
Create an empty vector in main called theVect. Ask the user for a number. Fill the vector with 10 random numbers that are multiples of that number. So, for instance, if the user says 7, then you need to use a while loop and fill in the vector with any randomly generated number that is num % 7.
#include <iostream> #include <vector> #include <ctime> #include <cstdlib> using namespace std; int main() { srand(time(NULL)); vector<int> theVect; int n; cout << "Enter an integer: "; cin >> n; int i = 0; while (i < 10) { theVect.push_back(n * (rand() % 100)); i++; } // print the vector for (i = 0; i < 10; ++i) { cout << theVect[i] << " "; } cout << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.