Saturday 16 August 2014

How to create a two dimensional array in c++ program

Structure of the Problem Requirements 

In this problem we will learn how to create a two dimensional Array in C++ Program. Two Dimensional array are used when we have complex and large records in a sequence in programming. We always need nested for loops to access the records in two dimensional arrays . These loops working in the sequence as , one loop run on the indexing of the array and the second on the records of the arrays . Here is the source code of this problem which help in better understanding .

Source Code  


#include <iostream.h>
int main()
{
int myArray[5][3] = {                                     //Create Two'D Array
{1,2,3},                        //Initialize the Array with Integers
{4,5,6},
{7,8,9},
{10,11,12},
{13,14,15} };

for(int i = 0; i<5; i++)                                      // OutSide for Loop
{
cout<<endl;
for (int j = 0; j < 3; j++)                         //Inner side for loop in which data of Two'D Display
{
cout<<"\t"<<myArray[i][j];             //Display the Array
}
}
cout<<endl;
return 0;
}

Output of the Program

C++ Prgramming
Two Dimensional Array


Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment