Cpp Program of Filling and Printing 2D Array

ad+1

Filling and printing of Multidimensional array is bit tricky than that of one dimensional array. In this tutorial i am going to show you how to fill and print multidimensional array. As you can see in earlier tutorials that in single dimensional array we just used only single for loop, but in 2D array we will use for loop inside for loop or use can say nested loop. The reason is that in 2D array the data is arranged in rows and columns so for controlling row we use outer for loop and for controlling columns we use nested for loop. So let see how it works.


Program:
// Program By http://solutionscpp.blogspot.com
// Author Mansoor Ahmed
// GMail ID: secguy000@gmail.com

#include <iostream>
using namespace std;

int main()
{
int arr[5][5]={};  // Null Array

//Filling 2D array

cout<<"Filling Data: " <<endl;
for(int i=0; i<5; i++)
{
for(int j=0; j<5; j++)
{
cin>>arr[i][j];
}
}


//Printing 2D array

cout<<"\nPrinting Data: " <<endl;
for(int i=0; i<5; i++)
{
for(int j=0; j<5; j++)
{
cout<<arr[i][j];
}
}

} // End of Program



Output:


2 comments: Leave Your Comments

  1. I found nice article in your blog.thank you for useful info
    .

    ReplyDelete
  2. This heart information helps and simple to understand thanks to bloggers ' hard work.

    Garmentprinting

    ReplyDelete