Skip to content

Commit 2b0edc6

Browse files
committed
added 2d arrays in cpp
1 parent 8e5d583 commit 2b0edc6

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* 2 DIMENSIONAL ARRAYS
3+
*/
4+
5+
#include <iostream>
6+
using namespace std;
7+
int main()
8+
{
9+
int rows;
10+
int cols;
11+
cout << "Enter rows and cols of 2d array"<<endl;
12+
cin >> rows >> cols;
13+
int arr[rows][cols];
14+
cout << "Enter the elements of the array"<<endl;
15+
for(int i=0;i<rows;i++)
16+
{
17+
for(int j=0;j<cols;j++)
18+
{
19+
cin >> arr[i][j];
20+
}
21+
}
22+
cout << "Entered elements of 2d array"<<endl;
23+
for(int i=0;i<rows;i++)
24+
{
25+
for(int j=0;j<cols;j++)
26+
{
27+
if(j==cols-1)
28+
{
29+
cout << arr[i][j] << endl;
30+
}
31+
else
32+
{
33+
cout << arr[i][j] << " ";
34+
}
35+
}
36+
}
37+
}

C++/Data-Structures/ARRAYS/3darrays.cpp

Whitespace-only changes.

C++/Data-Structures/ARRAYS/4darrays.cpp

Whitespace-only changes.

C++/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
#### ARRAYS
1010

11+
* [ONE DIMENSIONAL ARRAY](Data-Structures/ARRAYS/1darrays.cpp)
12+
* [TWO DIMENSIONAL ARRAY](Data-Structures/ARRAYS/2darrays.cpp)
13+
* [THREE DIMENSIONAL ARRAY](Data-Structures/ARRAYS/3darrays.cpp)
14+
* [FOUR DIMENSIONAL ARRAY](Data-Structures/ARRAYS/4darrays.cpp)
15+
1116
#### LISTS
1217

1318
* LINKED-LIST

0 commit comments

Comments
 (0)