© 2026 schoolict.net (Ruwan Mangala Suraweera)
1.9 One-Dimensional Arraysඒක-මාන අරා
G.C.E. O/L Grade 11 ICT · Lesson 1G.C.E. O/L ICT · 11 ශ්රේණිය · පාඩම 1
In this videoමේ වීඩියෝවේ
- Array: many values, same type, one name.අරාව: බොහෝ අගයන්, එකම වර්ගය, එක් නමක්.
- Each value is an element; its position is the index.සෑම අගයක්ම අවයවයකි; එහි ස්ථානය දර්ශකයයි.
- Contiguous memory gives random (direct) access.එක ළඟ මතකය සෘජු ප්රවේශය දෙයි.
- Pascal array[1..5]; Python list from 0.Pascal array[1..5]; Python list 0 සිට.
- Loops fill, total and search arrays.ලූප අරා පුරවයි, එකතු කරයි, සොයයි.
Notesසටහන්
Syllabus 10.9. Imagine storing the marks of 40 students in 40 separate variables – Mark1, Mark2 … Mark40. Very messy! An array stores many values of the same data type under one name. Each value is an element, and we reach it with its index (position number), like Marks[3]. Arrays are kept in contiguous (side-by-side) memory, so any element can be reached directly (random access).විෂය නිර්දේශය 10.9. සිසුන් 40 දෙනෙකුගේ ලකුණු වෙනම විචල්ය 40 ක – Mark1, Mark2 … Mark40 – ගබඩා කිරීම ගැන සිතන්න. ඉතා අවුල්! අරාවක් (array) එකම දත්ත වර්ගයේ අගයන් බොහොමයක් එක් නමක් යටතේ ගබඩා කරයි. සෑම අගයක්ම අවයවයකි (element), අප එයට එහි දර්ශකය (index – ස්ථාන අංකය) මගින් ළඟා වෙමු, Marks[3] වැනි. අරා එක ළඟ පිහිටි (contiguous) මතකයේ තබන නිසා ඕනෑම අවයවයකට කෙළින්ම ළඟා විය හැක (random access).
1. Why do we need arrays?1. අරා අවශ්ය ඇයි?
- One name for many values – easy to read.බොහෝ අගයන්ට එක් නමක් – කියවීමට පහසුයි.
- Use a loop to process all elements with a few lines.පේළි කිහිපයකින් සියලු අවයව සැකසීමට ලූපයක් භාවිත කරන්න.
- Easy to find the total, average, highest and to search or sort.එකතුව, සාමාන්යය, ඉහළම අගය සොයා ගැනීමට, සෙවීමට හෝ පිළිවෙළට සැකසීමට පහසුයි.
- To change 5 students to 40, change one number only.සිසුන් 5 සිට 40 දක්වා වෙනස් කිරීමට එක් අංකයක් පමණක් වෙනස් කරන්න.
2. Index, elements and memory2. දර්ශකය, අවයව සහ මතකය
Think of a row of numbered lockers in a school corridor. All lockers are next to each other (contiguous), and you can open locker 4 directly without opening 1, 2 and 3 first (random access). The array Marks with 5 elements:පාසල් කොරිඩෝවක අංක කළ ලොකර් පේළියක් ගැන සිතන්න. සියලු ලොකර් එක ළඟ (contiguous) ඇති අතර 1, 2, 3 මුලින් නොවිවෘත කර ලොකර් 4 කෙළින්ම විවෘත කළ හැක (random access). අවයව 5ක් ඇති Marks අරාව:
| Pascal indexPascal දර්ශකය | 11 | 22 | 33 | 44 | 55 |
|---|---|---|---|---|---|
| Python indexPython දර්ශකය | 00 | 11 | 22 | 33 | 44 |
| Valueඅගය | 6565 | 8080 | 4545 | 9090 | 7070 |
3. Declare, assign and access3. ප්රකාශ කිරීම, පැවරීම සහ ප්රවේශය
| Actionක්රියාව | PascalPascal | PythonPython |
|---|---|---|
| Declare (5 integers)ප්රකාශ කිරීම (පූර්ණ සංඛ්යා 5) | var Marks: array[1..5] of integer;var Marks: array[1..5] of integer; | marks = [0, 0, 0, 0, 0]marks = [0, 0, 0, 0, 0] |
| Assign a valueඅගයක් පැවරීම | Marks[3] := 45;Marks[3] := 45; | marks[2] = 45marks[2] = 45 |
| Access (read) a valueඅගයක් කියවීම | writeln(Marks[3]);writeln(Marks[3]); | print(marks[2])print(marks[2]) |
| Fill with a loopලූපයකින් පිරවීම | for i := 1 to 5 do readln(Marks[i]);for i := 1 to 5 do readln(Marks[i]); | for i in range(5): marks[i] = int(input())for i in range(5): marks[i] = int(input()) |
4. Example: total, average and highest4. උදාහරණය: එකතුව, සාමාන්යය සහ ඉහළම
📝 Pseudocodeව්යාජ කේතය (Pseudocode)
BEGIN FOR i = 1 TO 5 INPUT Marks[i] ENDFOR Total = 0 Highest = Marks[1] FOR i = 1 TO 5 Total = Total + Marks[i] IF Marks[i] > Highest THEN Highest = Marks[i] ENDIF ENDFOR DISPLAY Total, Total / 5, Highest END
program MarksArray; var marks: array[1..5] of integer; i, total, highest: integer; begin for i := 1 to 5 do begin write('Enter mark ', i, ': '); readln(marks[i]); end; total := 0; highest := marks[1]; for i := 1 to 5 do begin total := total + marks[i]; if marks[i] > highest then highest := marks[i]; end; writeln('Total = ', total); writeln('Average = ', total / 5:0:2); writeln('Highest = ', highest); end.
marks = [0, 0, 0, 0, 0] # 5 elements, index 0 to 4 for i in range(5): marks[i] = int(input(f"Enter mark {i + 1}: ")) total = 0 highest = marks[0] for i in range(5): total = total + marks[i] if marks[i] > highest: highest = marks[i] print("Total =", total) print(f"Average = {total / 5:.2f}") print("Highest =", highest)
▶ Sample runනියැදි ධාවනය · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter mark 1: 65 Enter mark 2: 80 Enter mark 3: 45 Enter mark 4: 90 Enter mark 5: 70 Total = 350 Average = 70.00 Highest = 90
| ii | Marks[i]Marks[i] | TotalTotal | Marks[i] > Highest ?Marks[i] > Highest ? | HighestHighest |
|---|---|---|---|---|
| 11 | 6565 | 6565 | Noනැත | 6565 |
| 22 | 8080 | 145145 | Yesඔව් | 8080 |
| 33 | 4545 | 190190 | Noනැත | 8080 |
| 44 | 9090 | 280280 | Yesඔව් | 9090 |
| 55 | 7070 | 350350 | Noනැත | 9090 |
Total = 350 and Highest = 90, the same as the real program output. Average = 350 ÷ 5 = 70.00.Total = 350 සහ Highest = 90, සැබෑ වැඩසටහන් ප්රතිදානයට සමානයි. සාමාන්යය = 350 ÷ 5 = 70.00.
5. Example: searching an array (linear search)5. උදාහරණය: අරාවක සෙවීම (රේඛීය සෙවීම)
The array Nums holds 12, 45, 7, 30, 18. To find a number, check each element from the first to the last. This is called a linear search.Nums අරාවේ 12, 45, 7, 30, 18 ඇත. සංඛ්යාවක් සොයා ගැනීමට, සෑම අවයවයක්ම පළමුවැන්නේ සිට අවසානය දක්වා පරීක්ෂා කරන්න. මෙය රේඛීය සෙවීම (linear search) ලෙස හැඳින්වේ.
📝 Pseudocodeව්යාජ කේතය (Pseudocode)
BEGIN Nums = [12, 45, 7, 30, 18] INPUT Key Pos = 0 FOR i = 1 TO 5 IF Nums[i] = Key THEN Pos = i ENDIF ENDFOR IF Pos > 0 THEN DISPLAY "Found at position ", Pos ELSE DISPLAY "Not found" ENDIF END
program SearchArray; var nums: array[1..5] of integer; i, key, pos: integer; begin nums[1] := 12; nums[2] := 45; nums[3] := 7; nums[4] := 30; nums[5] := 18; write('Enter number to find: '); readln(key); pos := 0; for i := 1 to 5 do if nums[i] = key then pos := i; if pos > 0 then writeln('Found at position ', pos) else writeln('Not found'); end.
nums = [12, 45, 7, 30, 18] key = int(input("Enter number to find: ")) pos = 0 for i in range(5): if nums[i] == key: pos = i + 1 # position counted from 1 if pos > 0: print("Found at position", pos) else: print("Not found")
▶ Sample runනියැදි ධාවනය 1 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter number to find: 30 Found at position 4
▶ Sample runනියැදි ධාවනය 2 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter number to find: 50 Not found
| ii | Nums[i]Nums[i] | Nums[i] = 30 ?Nums[i] = 30 ? | PosPos |
|---|---|---|---|
| 11 | 1212 | Noනැත | 00 |
| 22 | 4545 | Noනැත | 00 |
| 33 | 77 | Noනැත | 00 |
| 44 | 3030 | Yesඔව් | 44 |
| 55 | 1818 | Noනැත | 44 |
6. Finding a position6. ස්ථානයක් සොයා ගැනීම
Temperatures (°C) in Colombo for a week are stored in an array. The program keeps the index of the highest value, not just the value, so it can tell us which day was hottest.සතියක කොළඹ උෂ්ණත්ව (°C) අරාවක ගබඩා කර ඇත. වැඩසටහන ඉහළම අගය පමණක් නොව එහි දර්ශකයද තබා ගන්නා නිසා කුමන දිනය උණුසුම්ම වූයේදැයි කිව හැක.
program HottestDay; var t: array[1..7] of integer; i, best: integer; begin t[1] := 31; t[2] := 33; t[3] := 30; t[4] := 34; t[5] := 32; t[6] := 29; t[7] := 33; best := 1; for i := 2 to 7 do if t[i] > t[best] then best := i; writeln('Day ', best, ': ', t[best]); end.
t = [31, 33, 30, 34, 32, 29, 33] best = 0 for i in range(1, 7): if t[i] > t[best]: best = i print("Day " + str(best + 1) + ":", t[best])
▶ Sample runනියැදි ධාවනය · same output in Pascal and PythonPascal සහ Python දෙකෙහිම එකම ප්රතිදානය
Day 4: 34
Key Wordsප්රධාන පද
Sample Q&Aආදර්ශ ප්රශ්න සහ පිළිතුරු
1What is an array?අරාවක් යනු කුමක්ද?
2What is an index?දර්ශකයක් යනු කුමක්ද?
3What does “random access” mean for arrays?අරා සඳහා “random access” යන්නෙහි තේරුම කුමක්ද?
4Declare an integer array of 5 elements in Pascal.Pascal හි අවයව 5ක පූර්ණ සංඛ්යා අරාවක් ප්රකාශ කරන්න.
5In Python, what is the index of the first element?Python හි පළමු අවයවයේ දර්ශකය කුමක්ද?
6For marks 65, 80, 45, 90, 70 what is the highest?ලකුණු 65, 80, 45, 90, 70 සඳහා ඉහළම කුමක්ද?
MCQබහුවරණ ප්රශ්න
Choose the correct answer for each question.සෑම ප්රශ්නයකටම නිවැරදි පිළිතුර තෝරන්න.
1An array stores many values of…අරාවක් බොහෝ අගයන් ගබඩා කරන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Same type.එකම වර්ගය.
2One value inside an array is called an…අරාවක් තුළ ඇති එක් අගයක් හඳුන්වන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Element.අවයවය.
3The position number of an element is its…අවයවයක ස්ථාන අංකය එහි…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Index.දර්ශකය.
4Array elements are stored in…අරා අවයව ගබඩා වන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Side by side.එක ළඟ.
5Reaching Marks[4] without reading Marks[1..3] is called…Marks[1..3] නොකියවා Marks[4] ට ළඟා වීම හඳුන්වන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Direct.සෘජු.
6Correct Pascal declaration of an array of 5 integers:පූර්ණ සංඛ්යා 5ක අරාවක නිවැරදි Pascal ප්රකාශනය:
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Pascal syntax.Pascal වාක්ය රීතිය.
7In Python, the first element of marks is…Python හි marks හි පළමු අවයවය…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Index from 0.0 සිට දර්ශකය.
8A Python list of 5 elements has its last index…අවයව 5ක Python list එකක අවසාන දර්ශකය…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
0 to 4.0 සිට 4.
9Marks = 65, 80, 45, 90, 70 (Pascal). Marks[3] is…Marks = 65, 80, 45, 90, 70 (Pascal). Marks[3]…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Third element.තුන්වන අවයවය.
10The total of 65, 80, 45, 90 and 70 is…65, 80, 45, 90 සහ 70 හි එකතුව…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Sum.එකතුව.
11Nums = 12, 45, 7, 30, 18. Searching for 30 gives…Nums = 12, 45, 7, 30, 18. 30 සෙවීමෙන් ලැබෙන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Fourth element.හතරවන අවයවය.
12Searching for 50 in the same array gives…එම අරාවේම 50 සෙවීමෙන් ලැබෙන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Not in the array.අරාවේ නැත.
13Checking elements one by one from the start is a…ආරම්භයේ සිට එකින් එක අවයව පරීක්ෂා කිරීම…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Linear.රේඛීය.
14Which statement assigns 45 to the third element in Python?Python හි තුන්වන අවයවයට 45 පවරන ප්රකාශය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Index 2 = third.දර්ශකය 2 = තුන්වන.
15Temperatures 31, 33, 30, 34, 32, 29, 33. The hottest day is…උෂ්ණත්ව 31, 33, 30, 34, 32, 29, 33. උණුසුම්ම දිනය…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
34 is 4th.34 හතරවැන්නයි.
MCQ answer keyMCQ පිළිතුරු
- A – Same type.එකම වර්ගය.
- B – Element.අවයවය.
- A – Index.දර්ශකය.
- C – Side by side.එක ළඟ.
- C – Direct.සෘජු.
- D – Pascal syntax.Pascal වාක්ය රීතිය.
- B – Index from 0.0 සිට දර්ශකය.
- A – 0 to 4.0 සිට 4.
- B – Third element.තුන්වන අවයවය.
- C – Sum.එකතුව.
- A – Fourth element.හතරවන අවයවය.
- C – Not in the array.අරාවේ නැත.
- D – Linear.රේඛීය.
- D – Index 2 = third.දර්ශකය 2 = තුන්වන.
- B – 34 is 4th.34 හතරවැන්නයි.
Structured Questionsව්යුහගත ප්රශ්න
1(i) What is a one-dimensional array? (1 mark)
(ii) Give two advantages of using an array instead of separate variables. (2 marks)(i) ඒක-මාන අරාවක් යනු කුමක්ද? (ලකුණු 1)
(ii) වෙනම විචල්ය වෙනුවට අරාවක් භාවිතයේ වාසි දෙකක් දෙන්න. (ලකුණු 2) (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
2Explain the terms (a) index (b) contiguous memory (c) random access. (3 marks)(a) දර්ශකය (b) එක ළඟ පිහිටි මතකය (c) සෘජු ප්රවේශය යන පද පහදන්න. (ලකුණු 3) (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
3Write a program (Pascal or Python) to read 5 marks into an array and display the total, average and highest mark. (6 marks)ලකුණු 5ක් අරාවකට කියවා එකතුව, සාමාන්යය සහ ඉහළම ලකුණ පෙන්වන වැඩසටහනක් (Pascal හෝ Python) ලියන්න. (ලකුණු 6) (6 marksලකුණු 6)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
program MarksArray; var marks: array[1..5] of integer; i, total, highest: integer; begin for i := 1 to 5 do begin write('Enter mark ', i, ': '); readln(marks[i]); end; total := 0; highest := marks[1]; for i := 1 to 5 do begin total := total + marks[i]; if marks[i] > highest then highest := marks[i]; end; writeln('Total = ', total); writeln('Average = ', total / 5:0:2); writeln('Highest = ', highest); end.
marks = [0, 0, 0, 0, 0] # 5 elements, index 0 to 4 for i in range(5): marks[i] = int(input(f"Enter mark {i + 1}: ")) total = 0 highest = marks[0] for i in range(5): total = total + marks[i] if marks[i] > highest: highest = marks[i] print("Total =", total) print(f"Average = {total / 5:.2f}") print("Highest =", highest)
▶ Sample runනියැදි ධාවනය · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter mark 1: 65 Enter mark 2: 80 Enter mark 3: 45 Enter mark 4: 90 Enter mark 5: 70 Total = 350 Average = 70.00 Highest = 90
4Nums = 12, 45, 7, 30, 18. Complete a trace table for a linear search for 30 and give the output. (4 marks)Nums = 12, 45, 7, 30, 18. 30 සඳහා රේඛීය සෙවීමක අනුරේඛන වගුවක් සම්පූර්ණ කර ප්රතිදානය දෙන්න. (ලකුණු 4) (4 marksලකුණු 4)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
| ii | Nums[i]Nums[i] | Nums[i] = 30 ?Nums[i] = 30 ? | PosPos |
|---|---|---|---|
| 11 | 1212 | Noනැත | 00 |
| 22 | 4545 | Noනැත | 00 |
| 33 | 77 | Noනැත | 00 |
| 44 | 3030 | Yesඔව් | 44 |
| 55 | 1818 | Noනැත | 44 |
5Write Pascal and Python statements to (a) store 45 in the third element of Marks (b) display the first element. (4 marks)(a) Marks හි තුන්වන අවයවයේ 45 ගබඩා කිරීමට (b) පළමු අවයවය පෙන්වීමට Pascal සහ Python ප්රකාශ ලියන්න. (ලකුණු 4) (4 marksලකුණු 4)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
🎮 Game🎮 ක්රීඩා
Summary & Downloadsසාරාංශය සහ බාගත කිරීම්
Key pointsප්රධාන කරුණු
- Array: many values, same type, one name.අරාව: බොහෝ අගයන්, එකම වර්ගය, එක් නමක්.
- Element = one value; index = its position.අවයවය = එක් අගයක්; දර්ශකය = එහි ස්ථානය.
- Contiguous memory → random (direct) access.එක ළඟ මතකය → සෘජු ප්රවේශය.
- Pascal: array[1..5] of integer.Pascal: array[1..5] of integer.
- Python list index starts at 0.Python list දර්ශකය 0 න් ආරම්භ වේ.
- Use a loop to fill and process an array.අරාවක් පිරවීමට සහ සැකසීමට ලූපයක් භාවිත කරන්න.
- Total, average, highest with one loop.එක් ලූපයකින් එකතුව, සාමාන්යය, ඉහළම.
- Linear search checks elements one by one.රේඛීය සෙවීම අවයව එකින් එක පරීක්ෂා කරයි.
