Lab Manual 10 + 11
Lab Manual 10 + 11
name = customers[0][0]
email = customers[0][1]
dateofbirth = customers[0][2]
A two-dimensional array:
int arr[2][3];
This array has total 2*3 = 6 elements.
A three-dimensional array:
int arr[2][2][2];
This array has total 2*2*2 = 8 elements.
Two-dimensional array
Let’s see how to declare, initialize and access Two Dimensional Array elements.
int myarray[2][3];
Initialization:
We can initialize the array in many ways:
Method 1:
int main(){
int arr[2][3] = {{11, 22, 33}, {44, 55, 66}};
for(int i=0; i<2;i++){
for(int j=0; j<3; j++){
cout<<"arr["<<i<<"]["<<j<<"]: "<<arr[i][j]<<endl;
}
}
return 0;
}
Output:
arr[0][0]: 11
arr[0][1]: 22
arr[0][2]: 33
arr[1][0]: 44
arr[1][1]: 55
arr[1][2]: 66
Lab Tasks
Task 1
Write a C++ program to find the sum and difference of two, two dimensional arrays of size 2*2.
Sample output: