Two Dimensional Array
What is a Two Dimensional array in C++?
Explanation
"
Two Dimensional Array" is a simple form of multi-dimensional array that stores the array elements in a
row, column matrix format.
Syntax:
type array_name[array_size1][array_size2]
Example:
#include <iostream.h>
const int month=2;
const int subject=2;
void main()
{
int i,j;
int twodim[month][subject];
for(i=0;i
for(j=0;j
{
cout << "Enter value of month " << i+1;
cout <<",subject "<< j+1 <<":";
cin >> twodim[i][j];
}
cout << "\n\n\n";
cout << " subject\n";
cout << " 1 2";
for(i=0;i
{
cout << "\nmonth " << i+1;
for(j=0;j
{
cout << twodim[i][j];
}
}
}
|
Result:
Enter the value of month 1, subject 1:4
Enter the value of month 1, subject 2:4
Enter the value of month 2, subject 1:3
Enter the value of month 2, subject 2:3
subject
1 2
month 1 4 4
month 2 3 3
In the above example the array "twodim" is used to display the vaues of two subject for two months in a matrix
format.