In: Computer Science
Write an interactive program in c++ that allows the user to enter 2-15 vectors (use the if statement). Display the resultant on the screen.
Code
#include#include using namespace std; //to print void display(const vector >& V) { for (auto & i : V) { for (int j : i) { cout << j << " "; } cout << "\n"; } } int main() { //to store vectors vector > V; int value ; // to enter the number of vectors user wants cout<<"Enter the number of vector you want to add between 2-15"; cin >> value; int i = 0; // to store the value in each vector while (i < value && value >= 2 && value <= 15 ) { vector v; string val; cout << "Press null to stop entering integers in current vectors" << "\n"; cin >> val; // when to stop storing value in particular vector do { v.push_back(stoi(val)); cin >> val; } while (val != "null"); V.push_back(v); i++; } // printing result display(V); return 0; }
Output