1 / 14

計算機程式 C omputer Programming Language Lecture 5 陣列

計算機程式 C omputer Programming Language Lecture 5 陣列. 郭修伯 助理教授 (5488). 陣列 ( Array). 用一個變數儲存多個數值 一維陣列 Datatype name (size) integer student (40) type(person) student (students). 陣列型態. 陣列變數名稱. 陣列的容量( 使用宣告為 parameter 的常數 或直接用數字 ). 使用陣列注意事項. 存取陣列內容 student (1) = 89

Télécharger la présentation

計算機程式 C omputer Programming Language Lecture 5 陣列

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. 計算機程式Computer Programming LanguageLecture 5 陣列 郭修伯 助理教授 (5488)

  2. 陣列 (Array) • 用一個變數儲存多個數值 • 一維陣列 • Datatype name (size) • integer student (40) • type(person) student (students) 陣列型態 陣列變數名稱 陣列的容量(使用宣告為parameter的常數 或直接用數字)

  3. 使用陣列注意事項 • 存取陣列內容 • student(1) = 89 • 小心不要超出陣列容量 • 從 1 開始,和 C 語言中從 0 開始不一樣 • Fortran 77 語法 • integer a • dimension a (10)

  4. 使用自訂型態的一維陣列 二維陣列

  5. 二維 Fortran 90 Integer a(10,10) Integer a(1:10,1:10) Fortran 77 integer a dimension a(10,10) dimension a(1:10,1:10) 最多七維 配合迴圈

  6. 設定矩陣初值

  7. 此 where 指令和 do 迴圈效果一樣,但是 do 迴圈寫法的程式不能做平行處理 • where 指令是用來設定陣列的,也可以配合 elsewhere

  8. 範例:計算五個人的稅金 收入30萬以下稅率10%,30~50萬稅率為12%,50萬以上稅率為15% Try to use “do…if …”

  9. 陣列的儲存規則 • Integer A(5) • 在記憶體中的順序 A(1),A(2),A(3),A(4),A(5) • Integer A(2,3) • 在記憶體中的順序 A(1,1),A(2,1),A(1,2),A(2,2),A(1,3),A(2,3) • Integer A(2,2,2) • 在記憶體中的順序A(1,1,1),A(2,1,1),A(1,2,1),A(2,2,1),A(1,1,2),A(2,1,2),A(1,2,2),A(2,2,2) 和C語言正好相反

  10. Fortran 77 Fortran 90 可變大小的陣列

  11. 釋放記憶體空間

  12. 數字排序 交換兩個變數內容的方法

  13. 矩陣相乘

  14. 宣告容量為10的一維陣列,初值為2, 4, 6, … 20;計算10個數字的平均值 將費式數列前20項儲存在一個一維陣列 習題說明

More Related