Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dynamic Array Multidimensional Array Matric Operation with Array

Similar presentations


Presentation on theme: "Dynamic Array Multidimensional Array Matric Operation with Array"— Presentation transcript:

1 Dynamic Array Multidimensional Array Matric Operation with Array
Arrays Dynamic Array Multidimensional Array Matric Operation with Array

2 Dynamic array

3 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

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

5 Multidimensional array

6 How do you create it? Declare it using:

7 How to read it/display it

8 Actually it is…

9 Example

10 Example: Output

11 Matric operation with array

12 How to do multiplication

13 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

14 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 x 1 = 4

15 But how to do that in C++?

16 But how to do that in C++? We iterate first Array but according to “m” value (MAX ROW)

17 But how to do that in C++? We iterate second Array according to the “q” value (MAX COLUMN)

18 But how to do that in C++? We let all the content = 0 for the first time

19 But how to do that in C++? K is for storing the result of multiplication. P is MAX ROW for SECOND ARRAY

20 But how to do that in C++? Remember to add c[i][j] for next “k” iteration after multiplication

21 Matrix Operation with Array
Refer source code explanation


Download ppt "Dynamic Array Multidimensional Array Matric Operation with Array"

Similar presentations


Ads by Google