im making a program which displays a multiplication table, which the user prompts the number of rows and columns, this program displays the table but the number of columns and rows should be the same, if i input a different number,an error happens.
#include <iostream>
using namespace std;
int main()
{
int r,c;
cout<<"How many rows?: ";
cin>>r;
cout<<"How many Columns?: ";
cin>>c;
int table[r][c];
//assigns each element
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= c; j++)
{
table[i][j] = i * j;
}
}
//prints the table
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= c; j++)
{
cout << table[i][j] << '\t';
}
}
system("pause");
return 0;
}