Write a program to find the table of numbers using a while loop. Your program should ask the size of the table. That size defines the rows and columns. Use while loop only for this program.
#include<iostream>
#include<vector>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int rows, columns;
cout << "Please, enter a number of rows: ";
cin >> rows;
cout << "Please, enter a number of columns: ";
cin >> columns;
cout << "Make a table with random numbers from 0 to 100:";
vector<vector<int> >table(rows, vector<int>(columns));
srand(static_cast<unsigned int>(time(0)));
for (int i = 0; i < rows; i++)
for (int j = 0; j < columns; j++)
table[i][j] = rand()%100;
cout << "\nResulting table: \n";
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
cout << table[i][j]<<" ";
}
cout << endl;
}
}
Comments
Leave a comment