C++ Program to Scan and Print Matrix

Write C++ Program to Scan and Print Matrix

// CPP Program to Scan and Print Matrix

#include <iostream>

using namespace std;

int main()
{
	int A[3][3], i, j;


	for(i = 0; i < 3 ; i++)
	{
		for(j = 0; j < 3; j++)
		{
			cout << "Enter A[" << i << "][" << j << "] :--> ";
			cin >> A[i][j];
		}
	}

	cout << "\nThe matrix is :--> \n";
	for(i = 0; i < 3 ; i++)
	{
		for(j = 0; j < 3; j++)
		{
			cout << A[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

Output:

Enter A[0][0] :--> 1
Enter A[0][1] :--> 2
Enter A[0][2] :--> 3
Enter A[1][0] :--> 4
Enter A[1][1] :--> 5
Enter A[1][2] :--> 6
Enter A[2][0] :--> 7
Enter A[2][1] :--> 8
Enter A[2][2] :--> 9

The matrix is :-->
1  2  3
4  5  6
7  8  9

≪ Previous | Next ≫