codescracker


c++

C++ Two Dimensional Array Program



« Previous Program Next Program »


Two Dimensional Array Program in C++

Two dimensional (2D) array can be made in C++ programming language by using two for loops, first is outer for loop and the second one is inner for loop. The outer for loop is responsible for rows and the inner for loop is responsible for columns as shown here in the following program.

C++ Programming Code for Two Dimensional (2D) Array

Following C++ program ask to the user to enter row and column size of the array then ask to the user to enter array elements, and the program will display the array elements in two dimensional (i.e., display array elements in row and column):

/* C++ Program - Two Dimensional Array Program */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int arr[10][10], row, col, i, j;
	cout<<"Enter number of row for Array (max 10) : ";
	cin>>row;
	cout<<"Enter number of column for Array (max 10) : ";
	cin>>col;
	cout<<"Now Enter "<<row<<"*"<<col<<" Array Elements : ";
	for(i=0; i<row; i++)
	{
		for(j=0; j<col; j++)
		{
			cin>>arr[i][j];
		}
	}
	cout<<"The Array is :\n";
	for(i=0; i<row; i++)
	{
		for(j=0; j<col; j++)
		{
			cout<<arr[i][j]<<" ";
		}
		cout<<"\n";
	}
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

two dimensional array in c++ programming

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test