This Post Contains A C++ Program For Printing A 2D-Array [Two Dimensional] Onto The Screen/Console With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC/C++3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays', 'For-Loop' & 'Nested-Loops' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.
# Note : You Can Simply Copy-Paste The Following Code Into The Compiler For Direct Result.
C++ Program For Printing A 2D-Array [Two Dimensional] Onto The Screen/Console.
/* Declaration Of Header Files */
# include <iostream.h>
# include <conio.h>
/* Start Of Main Program */
void main()
{
/* Declaration Of Variables */
int i, j, r = 0, c = 0;
int a [ 10 ][ 10 ];
clrscr();
/* Asking For The Input From User */
cout << " Enter Number Of Rows & Columns Of 2D Array [ Matrix ] : ";
cin >> r >> c ;
// Accepting Values Of 2D Array [ Matrix ]
cout << " Enter " << r * c << " Values for 2D Array : ";
for ( i = 0; i < r; i++ )
{
for ( j = 0; j < c; j++ )
{
cin >> a [ i ][ j ];
}
}
// Printing Values Of 2D Array [ Matrix ]
cout << " Values Of 2D Array [ Matrix ] Are : ";
for ( i = 0; i < r; i++ )
{
cout << " \n ";
for ( j = 0; j < c; j++ )
{
cin >> a [ i ][ j ];
}
}
getch();
}
/* End Of Main Program */
Output :
Enter Number Of Rows & Columns Of 2D Array [ Matrix ] : 3 3
Enter 9 Values For 2D Array [ Matrix ] :
1 2 3 4 5 6 7 8 9
Values Of 2D Array [ Matrix ] Are :
1 2 3
4 5 6
7 8 9
# Note : You Can Simply Copy-Paste The Following Code Into The Compiler For Direct Result.
C++ Program For Printing A 2D-Array [Two Dimensional] Onto The Screen/Console.
/* Declaration Of Header Files */
# include <iostream.h>
# include <conio.h>
/* Start Of Main Program */
void main()
{
/* Declaration Of Variables */
int i, j, r = 0, c = 0;
int a [ 10 ][ 10 ];
clrscr();
/* Asking For The Input From User */
cout << " Enter Number Of Rows & Columns Of 2D Array [ Matrix ] : ";
cin >> r >> c ;
// Accepting Values Of 2D Array [ Matrix ]
cout << " Enter " << r * c << " Values for 2D Array : ";
for ( i = 0; i < r; i++ )
{
for ( j = 0; j < c; j++ )
{
cin >> a [ i ][ j ];
}
}
// Printing Values Of 2D Array [ Matrix ]
cout << " Values Of 2D Array [ Matrix ] Are : ";
for ( i = 0; i < r; i++ )
{
cout << " \n ";
for ( j = 0; j < c; j++ )
{
cin >> a [ i ][ j ];
}
}
getch();
}
/* End Of Main Program */
Output :
Enter Number Of Rows & Columns Of 2D Array [ Matrix ] : 3 3
Enter 9 Values For 2D Array [ Matrix ] :
1 2 3 4 5 6 7 8 9
Values Of 2D Array [ Matrix ] Are :
1 2 3
4 5 6
7 8 9