Presentation is loading. Please wait.

Presentation is loading. Please wait.

LAB-12 2-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.

Similar presentations


Presentation on theme: "LAB-12 2-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals."— Presentation transcript:

1 LAB-12 2-D Array I Putu Danu Raharja raharja @kfupm.edu.sa Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals

2 ICS101-LAB12-Term073 2 2-D Array Most common use is to manipulate matrices Stored contiguously in memory like 1-D arrays (column-wise) PRINT and READ operation without subscript means column-wise

3 ICS101-LAB12-Term073 3 Declaration Two ways TYPE ANAME (R, C)→ Explicit DIMENSION ANAME (R, C)→ Implicit

4 ICS101-LAB12-Term073 4 Initialization Assignment Row-major Column-major User input Row-major Column-major

5 ICS101-LAB12-Term073 5 Row-major Assignment INTEGER IDENT (3, 3), ROW, COL DO 100 ROW = 1, 3 DO 100 COL = 1, 3 IF (ROW.EQ. COL) THEN IDENT (ROW, COL) = 1 ELSE IDENT (ROW, COL) = 0 ENDIF 100CONTINUE PRINT*, IDENT END

6 ICS101-LAB12-Term073 6 Column-wise Assignment Example INTEGER IDENT (3, 3), ROW, COL DO 100 COL = 1, 3 DO 100 ROW = 1, 3 IF (ROW.EQ. COL) THEN IDENT (ROW, COL) = 1 ELSE IDENT (ROW, COL) = 0 ENDIF 100CONTINUE PRINT*, IDENT END

7 ICS101-LAB12-Term073 7 Row-wise READ Example (1) INTEGER MAT (2, 3), ROW, COL DO 100 ROW = 1, 2 DO 100 COL = 1, 2 READ*, MAT (ROW, COL) 100CONTINUE PRINT*, MAT END

8 ICS101-LAB12-Term073 8 Row-wise READ Example (2) INTEGER MAT (2, 3), ROW, COL DO 100 ROW = 1, 2 READ*, (MAT (ROW, COL), COL = 1, 3) 100CONTINUE PRINT*, MAT END

9 ICS101-LAB12-Term073 9 Row-wise READ Example (3) INTEGER MAT (2, 3), ROW, COL READ*, ((MAT (ROW, COL), COL = 1, 3), ROW = 1, 2) PRINT*, MAT END

10 ICS101-LAB12-Term073 10 Column-wise READ Example (1) INTEGER MAT (2, 3), ROW, COL DO 100 COL = 1, 2 DO 100 ROW = 1, 3 READ*, MAT (ROW, COL) 100CONTINUE PRINT*, MAT END

11 ICS101-LAB12-Term073 11 Column-wise READ Example (2) INTEGER MAT (2, 3), ROW, COL DO 100 COL = 1, 2 READ*, (MAT (ROW, COL), ROW = 1, 3) 100CONTINUE PRINT*, MAT END

12 ICS101-LAB12-Term073 12 Column-wise READ Example (3) INTEGER MAT (2, 3), ROW, COL READ*, ((MAT (ROW, COL), ROW = 1, 2), COLUMN = 1, 3) END

13 ICS101-LAB12-Term073 13 Row-wise PRINT Example (1) DO 100 ROW = 1, 2 DO 100 COL = 1, 3 PRINT*, MAT (ROW, COL) 100CONTINUE

14 ICS101-LAB12-Term073 14 Row-wise PRINT Example (2) DO 100 ROW = 1, 2 PRINT*, (MAT (ROW, COL), COL = 1, 3) 100CONTINUE

15 ICS101-LAB12-Term073 15 Row-wise PRINT Example (3) PRINT*, ((MAT (ROW, COL), COL = 1, 3), ROW = 1, 2)

16 ICS101-LAB12-Term073 16 Exercises Read an Integer 2x3 matrix MAT. Calculate the sums of elements of each column and store the sums in a 1-D array TOTAL. Print MAT row-wise (2 lines) and TOTAL (1 line). Write a function to check if two 3x2 matrices are identical and show appropriate messages. Write a main program to test the function. Read two integer 2x2 matrices LMAT and RMAT. Calculate and show the multiplication of LMAT and RMAT. Write a function to transpose a MxN matrix. Write a main program to test the function.


Download ppt "LAB-12 2-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals."

Similar presentations


Ads by Google