Dynamic Array Multidimensional Array Matric Operation with Array Arrays Dynamic Array Multidimensional Array Matric Operation with Array
Dynamic array
How do you create Dynamic Array A dynamic array is an array whose size is determined when the program is running, not when you write the program
Example int main () { int i,n; int * p; cout << "How many numbers would you like to type? "; cin >> i; p= new (nothrow) int[i]; if (p == 0) cout << "Error: memory could not be allocated"; else for (n=0; n<i; n++) cout << "Enter number: "; cin >> p[n]; } cout << "You have entered: "; cout << p[n] << ", "; delete[] p; return 0;
Multidimensional array
How do you create it? Declare it using:
How to read it/display it
Actually it is…
Example
Example: Output
Matric operation with array
How to do multiplication
Rules of Multiplication Number of COLUMN for First ARRAY must be the same with Number of ROW for Second ARRAY You must properly define who is the First Array and who is the Second Array Example: Matrix 3 x 5 with Matrix 5 x 1 = RIGHT Matrix 2 x 6 with Matrix 2 x 4 = WRONG
Example Let say you have From the example, we first take “1” from (First Array) the first row first column multiply with “2” from (Second Array) the first row first column. Then PLUS (+) with “2” from (First Array) the first row second column multiply with “0” from (Second Array) the second row first column. We will have 1 x 2 + 2 x 1 = 4
But how to do that in C++?
But how to do that in C++? We iterate first Array but according to “m” value (MAX ROW)
But how to do that in C++? We iterate second Array according to the “q” value (MAX COLUMN)
But how to do that in C++? We let all the content = 0 for the first time
But how to do that in C++? K is for storing the result of multiplication. P is MAX ROW for SECOND ARRAY
But how to do that in C++? Remember to add c[i][j] for next “k” iteration after multiplication
Matrix Operation with Array Refer source code explanation