1 / 16

LAB-12 2-D Array

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-D Array. Most common use is to manipulate matrices Stored contiguously in memory like 1-D arrays (column-wise)

bebe
Download Presentation

LAB-12 2-D Array

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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. Declaration • Two ways • TYPE ANAME (R, C) → Explicit • DIMENSION ANAME (R, C) → Implicit

  4. Initialization • Assignment • Row-major • Column-major • User input • Row-major • Column-major

  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 100 CONTINUE PRINT*,IDENT END

  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 100 CONTINUE PRINT*, IDENT END

  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) 100 CONTINUE PRINT*, MAT END

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

  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. 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) 100 CONTINUE PRINT*, MAT END

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

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

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

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

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

  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.

More Related