# C++ | Reverse matrix using 2d array

Introduction

This program is to create reverse matrix of numbers using 2d arrays. The program below is given. The program is extendable by using more numbers for matrix. Go enjoy the program. Lets begin……

Program to create reverse matrix using 2d array

``````
#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type int
int a[3][3],i,j;
//Input the numbers
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"Enter number :";
cin>>a[i][j];
}
}
//display the matrix
for(i=2;i>=0;i--)
{
for(j=2;j>=0;j--)
{
cout<<a[i][j]<<"\t";
}
cout<<endl;
}
//get character
getch();
}
``````

Output

Enter the number
1
Enter the number
2
Enter the number
3
Enter the number
4
Enter the number
5
Enter the number
6
Enter the number
7
Enter the number
8
Enter the number
9
9 8 7
6 5 4
3 2 1

//The above output looks great in c++. but blog does not show “\t” tabs. Sorry….

How does it work

1. You enter the number.
2. The number is saved in respective array.
3. The numbers are taken in reverse are printed to form matrix.

Extending it

The program can be extended by using more numbers and making the matrix more bigger.

Explanation.

1. Include ‘iostream.h’ and ‘conio.h’ files.
3. Start program by first clearing the screen.
4. Declare the variables as int (name them as you want.)
5. Add the cout and cin of array.
6. Add for loop to print the matrix.

At the end

You learnt creating the C++ program of Creating reverse matrix of numbers using 2d array. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Sharing options: