Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

This c++ program initializes a 2d array of size 3x3, prints its elements row-wise using nested for loops, and then terminates. It can be used as an example of array declaration, initialization, and traversal in c++ programming.

What you will learn

  • What is the size of the 2D array in this C++ program?
  • How is the 2D array printed in this C++ program?
  • How is the 2D array initialized in this C++ program?

Typology: Assignments

2020/2021

Uploaded on 02/13/2021

tau123
tau123 🇮🇳

8 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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; }