0
#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";
    }
}
3
Contributors
4
Replies
22
Views
1 Year
Discussion Span
Last Post by basit_3
Featured Replies
  • 3

    It'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 … Read More

3

It'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 correct forms would be "1st" and "2nd" (also "0th" isn't very pretty, you should probably add one the index when displaying it, so that the first item is referred to as the first, rather than the zeroth).

Comments
Exactly. Descriptions are important
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.