Putting it together · การรวมกัน
Putting it together
- A real algorithm joins the pieces: arrays, loops and selection.
- The exam's standard methods are totalling, counting, linear search, and finding the maximum or minimum.
การรวมกัน
- อัลกอริทึมจริงจะรวมชิ้นส่วนเข้าด้วยกัน: arrays, loops และ selection
- วิธีการมาตรฐาน ของการทดสอบได้แก่ การรวมผล, การนับ, การค้นหาแบบเชิงเส้น และการหาค่าสูงสุดหรือต่ำสุด
DECLARE A : ARRAY[1:5] OF INTEGER
DECLARE I, Total : INTEGER
FOR I ← 1 TO 5
A[I] ← I * 10
NEXT I
Total ← 0
FOR I ← 1 TO 5
Total ← Total + A[I]
NEXT I
OUTPUT Total
Totalling an array · การรวมค่าในอาร์เรย์
Totalling — start at 0, then add each array item as the loop visits it. · การรวม — เริ่มต้นที่ 0, แล้วบวกแต่ละรายการในอาร์เรย์เมื่อลูปเข้าถึง
Searching and counting
- Linear search: check each item, and set a flag if you find the target.
- Counting: add 1 to a counter each time a rule is true.
Searching and counting
- การค้นหาแบบเชิงเส้น: ตรวจสอบแต่ละรายการ และกำหนดค่าตัวบ่งชี้หากพบเป้าหมายที่ต้องการ
- การนับ: เพิ่ม 1 ไปยังตัวนับทุกครั้งเมื่อเงื่อนไขเป็นจริง
DECLARE A : ARRAY[1:5] OF INTEGER
DECLARE I, Target : INTEGER
DECLARE Found : BOOLEAN
FOR I ← 1 TO 5
A[I] ← I * 10
NEXT I
Target ← 30
Found ← FALSE
FOR I ← 1 TO 5
IF A[I] = Target
THEN
Found ← TRUE
ENDIF
NEXT I
OUTPUT Found
Common mistakes
- Plan the structure before you write the pseudocode.
- Match the exam's keywords and layout exactly.
ข้อผิดพลาดที่พบบ่อย
- Plan the structure before you write the pseudocode.
- Match the exam's keywords and layout exactly.
Now you try
- Each task uses an array that is filled for you — write the algorithm.
- Press Check answer to test it.
ลองดูเลย
- แต่ละงานใช้-array ที่มีการกรอกข้อมูลให้แล้ว — ให้เขียนอัลกอริทึม
- กด Check answer เพื่อทดสอบ
The array A is filled for you. Total all 5 values and output Total = then the total (it is 25). · อาร์เรย์ A ถูกเติมให้แล้ว. รวมทั้ง 5 ค่าและแสดงผล Total = ตามด้วยผลรวม (คือ 25)
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
The array A is filled for you. Use a linear search to set Found to TRUE if 9 is in the array, then output Found. · อาร์เรย์ A ถูกเติมให้แล้ว. ใช้ linear search เพื่อตั้ง Found เป็น TRUE หาก 9 อยู่ในอาร์เรย์, แล้วแสดงผล Found
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
The array A is filled for you. Count how many values are greater than 4, then output the count (it is 3). · อาร์เรย์ A ถูกเติมให้แล้ว. นับว่ามีค่าใด มากกว่า 4 beberapa, แล้วแสดงผลนับ (คือ 3)
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่