#include <iostream>
using namespace std;
main()
{
int matrix[2][2];
for (int i = 0; i<=2; i++)
{
for (int j = 0; j<=2; j++)
{
cout <<"Please Enter matrix "<<i<<"th row and "<<j<<"th Column ";
cin >>matrix[i][j];
}
}
//Display the Matrix
for (int i = 0; i <= 2; i++)
{
for (int j = 0; j <= 2; j++)
{
cout <<matrix[i][j]<<" ";
}
cout <<"\n";
}
}
Ihteshamullhaq
0
Newbie Poster
Recommended Answers
Jump to PostIt'd have helped us if you had described in what way the code did not behave as expected, but your problem is that you access the matrix out of bounds (the matrix can hold 2x2 items, but you're trying to store 3x3).
Also you're printing "1th" and "2th" when the …
All 4 Replies
Ihteshamullhaq
0
Newbie Poster
sepp2k
378
Practically a Master Poster
tobyITguy
commented:
Exactly. Descriptions are important
+1
Ihteshamullhaq
0
Newbie Poster
basit_3
0
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.