I made an array matrix and used for loops, the problem is that it only displays my last input. Please refer to the sample result below.
#include<iostream>
using namespace std;
int main()
{
int x = 0, y = 0;
int a[x][y], i, j;
cout<<"Enter number of Columns: ";
cin>>y;
cout<<"Enter number of Rows: ";
cin>>x;
cout<<endl;
for(i=0; i<x; i )
{
cout<<endl;
cout<<"Enter values or row/s: ";
cout<<endl;
for(j=0; j<y; j )
{
cout<<endl;
cout<<"Row "<< i 1 << ": ";
cin >> a[i][j];
}
}
cout<<endl;
cout<<"Entered Matrix is: ";
cout<<endl;
for(i=0; i<x; i )
{
for(j=0; j<y; j )
cout<<a[i][j]<<" ";
cout<<endl;
}
}
SAMPLE RESULT:
Enter number of Columns: 3
Enter number of Rows: 2
Enter values or row/s:
Row 1: -1
Row 1: -2
Row 1: -3
Enter values or row/s:
Row 2: 4
Row 2: 5
Row 2: -6
Entered Matrix is:
4 5 -6
4 5 -6
CodePudding user response:
Just change declaration of array like this:
int[x][y] to int[10][10]