#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";
    }
}

Please tell me what is wrong with this code

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).

commented: Exactly. Descriptions are important +1

your matrix should be matrix[3][3]

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.