-
Notifications
You must be signed in to change notification settings - Fork 11
/
arrays.cpp
40 lines (29 loc) · 843 Bytes
/
arrays.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
//Initialisation of arrays : 1-D array.
int firstArray[5] = {1,2,3,4,5};
cout << "Output of firstArray: \n";
for (int i = 0; i < 5; ++i) {
cout << firstArray[i] << '\t';
}
//Initialisation of 2-D array as row major.
int secondArray[5][2] = {1,2,3,4,5,6,7,8,9,0};
cout << "\n\nOutput of secondArray: \n";
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 2; ++j) {
cout << secondArray[i][j] << '\t';
}
cout << endl;
}
//Initialisation of 2-D array (Another method)
int thirdArray[2][5] = {{1,2,3,4,5},{6,7,8,9,0}};
cout << "\n\nOutput of thirdArray: \n";
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 5; ++j) {
cout << thirdArray[i][j] << '\t';
}
cout << endl;
}
return 0;
}