Docsity

C++ Program to Print a 2D Array, Assignments of Data Structures and Algorithms

Toggle sidebar
bg1
#include <iostream>
using namespace std;
int main()
{
int test[3][3]; //declaration of 2D array
test[0][0]=5; //initialization
test[0][1]=10;
test[1][1]=15;
test[1][2]=20;
test[2][0]=30;
test[2][2]=10;
//traversal
for(int i = 0; i < 3; ++i)
{
for(int j = 0; j < 3; ++j)
{
cout<< test[i][j]<<" ";
}
cout<<"\n"; //new line at each row
}
return 0;
}

Partial preview of the text

Download C++ Program to Print a 2D Array and more Assignments Data Structures and Algorithms in PDF only on Docsity!

#include using namespace std; int main() { int test[3][3]; //declaration of 2D array test[0][0]=5; //initialization test[0][1]=10; test[1][1]=15; test[1][2]=20; test[2][0]=30; test[2][2]=10; //traversal for(int i = 0; i < 3; ++i) { for(int j = 0; j < 3; ++j) { cout<< test[i][j]<<" "; } cout<<"\n"; //new line at each row } return 0; }