Download presentation
Presentation is loading. Please wait.
Published byFelicia Copeland Modified over 9 years ago
1
Multidimensional Array: อนันต์ ผลเพิ่ม Anan Phonphoem anan@cpe.ku.ac.th
2
One dimensional Array Type ScoreArr = array[1..6] of integer; var score: ScoreArr; 90 75 40 67 55 30 Score[1] Score[2] Score[3] Score[4] Score[5] Score[6]
3
Election Score Type ScoreArr = array[1..6] of integer; var Score: ScoreArr; 90 75 40 67 55 30 Score 1 2 3 4 5 6 Candidate #
4
Election: 3 districts 90 75 40 67 55 30 Type ScoreArr = array[1..6] of integer; var scoreD1, scoreD2, scoreD3: ScoreArr; 10 5 60 72 12 44 34 78 9 22 66 3 ScoreD1ScoreD2ScoreD3 1 2 3 4 5 6 Candidate #
5
2-dimensional array 90 75 40 67 55 30 10 5 60 72 12 44 34 78 9 22 66 3 ScoreD1ScoreD2ScoreD3 90 75 40 67 55 30 10 5 60 72 12 44 34 78 9 22 66 3 1 2 3 4 5 6 Score
6
2-dimensional array 90 75 40 67 55 30 10 5 60 72 12 44 34 78 9 22 66 3 1 2 3 4 5 6 Score Candidate #District 123 Score[candidate, district] Score[1,1] = Score[4,2] = Score[5,3] =
7
2-dimensional array 90 75 40 67 55 30 10 5 60 72 12 44 34 78 9 22 66 3 1 2 3 4 5 6 Score 123 Type Score2Arr = array[1..6,1..3] of integer; var Score: Score2Arr;
8
Accessing Array elements Score[1,1] = 10 For I := 1 to 6 do Readln(Score[I,1]); For candidate := 1 to 6 do For district := 1 to 3 do Readln(Score[candidate, district]); For district := 1 to 3 do Writeln(Score[3,district]);
9
Practice 1 Write a program to find the winner of the election in each district Write a program to find the winner of the election 90 75 40 67 55 30 10 5 60 72 12 44 34 78 9 22 66 3 1 2 3 4 5 6 Score 123
10
Practice 2 Write a program to add two table 432 671 441 399 123 231 357 109 555 8102 798 4918 +=
11
Practice 3 Write an O-X game (Tic-Tac-Toe)
12
3-dimensional array X X - - - X X - - X - - 1 2 3 4 123 - - - X - X X X - X - X 123 8 PM Midnight Movie Title: Men in Black II Seat[round, row, col] Seat[Evening, 3, 1] = Available; Seat[Midnight, 2, 4] = Taken;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.