Answer to Question #327924 in C++ for Eliyan

Question #327924

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.


1
Expert's answer
2022-04-12T13:26:00-0400
#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;
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS