1-D arrays · מصفوفة ثنائية الأبعاد 1
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · עמוד זה דורש דפדפן עדכני (תומך ב-SharedArrayBuffer). אנא עדכן את Chrome, Edge, Firefox או Safari לגרסה העדכנית ביותר.
English
A list of the same type
- An array holds a fixed number of values of one type.
- The guide's lower bound is 1 unless a question says otherwise.
- One index, in square brackets, picks an element.
עברית
רשימה מהסוג אותו
- מערך אחוסן מספר קבוע של ערכים מסוג אחד.
- הגבול התחתון במדריך הוא 1 אלא אם כן השאלה מציינת אחרת.
- אינדקס אחד, בסוגריים מרובעים, בוחר אלמנט.
English
עברית
DECLARE Score : ARRAY[1:5] OF INTEGER
Score[1] ← 4
Score[2] ← 8
OUTPUT Score[1]
English
A loop visits every cell
- A
FORloop from the lower bound to the upper bound is how you fill or read the array.
עברית
לולאה מבקרת בכל תא
- לולאת
FORמהגבול התחתון ועד לגבול העליון היא הדרך למלא או לקרוא את המערך.
DECLARE Score : ARRAY[1:3] OF INTEGER
Score[1] ← 4
Score[2] ← 8
Score[3] ← 6
DECLARE Total : INTEGER
Total ← 0
FOR I ← 1 TO 3
Total ← Total + Score[I]
NEXT I
OUTPUT Total
English
Watch out
Score[1]is the first cell when the array was declared[1:5].- The index can be an expression:
Score[I + 1].
עברית
שימו לב
Score[1]הוא התא הראשון כאשר המערך הוכרז כ-[1:5].- המדד יכול להיות ביטוי:
Score[I + 1].
English
Common mistakes
- Declare the array before you store into a cell.
- The index must stay inside the declared bounds.
עברית
טעויות נפוצות
- הכרז את המערך לפני שתאחסן ערך בתא.
- המדד חייב להישאר בתוך הגבולות שהוכרזו.
English
Now you try
- Store three numbers and total them.
עברית
כעת תנסו בעצמכם
- אחסן שלושה מספרים וחשב את הסכום שלהם.
Declare Score as ARRAY[1:3] OF INTEGER. Store 4 in cell 1 and output that cell. · גדר את Score כARRAY[1:3] OF INTEGER. אחסן את 4 בתא 1 והדפס תא זה.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
The array is filled for you. Total the three values and output the total (18). · המערך מלא עבורך. סכום את שלושת הערכים והדפס את הסכום (18).
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.