Arithmetic, DIV and MOD · การคำนวณทางคณิตศาสตร์, DIV และ MOD
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
Arithmetic operators
- Pseudocode uses
+-*/and^for the usual maths. /gives a real answer (with a decimal point).
ไทย
Arithmetic operators
- Pseudocode ใช้
+-*/และ^สำหรับคณิตศาสตร์ทั่วไป /ให้คำตอบเป็น real (มีจุดทศนิยม)
OUTPUT 6 + 2 // → 8
OUTPUT 6 * 2 // → 12
OUTPUT 7 / 2 // → 3.5
English
^ raises to a power
^means "to the power of".2 ^ 10is 2 multiplied by itself ten times, which is1024.- The syllabus lists it beside
+,-,*and/.
ไทย
^ ยกกำลัง
^หมายความว่า "ยกกำลัง"2 ^ 10คือ 2 คูณตัวเองสิบครั้ง ซึ่งเท่ากับ1024- หลักสูตรระบุไว้ข้าง
+,-,*และ/
OUTPUT 2 ^ 10 // → 1024
English
DIV: whole-number division
DIV(a, b)divides and throws the remainder away.DIV(17, 5)is3— 5 goes into 17 three whole times.- It is written like a function, with the two numbers in brackets — not between them.
ไทย
DIV: การหารจำนวนเต็ม
DIV(a, b)ทำการหารและทิ้งเศษออกDIV(17, 5)คือ3— 5 เข้าไปใน 17 ได้สามจำนวนเต็ม- เขียนเหมือนฟังก์ชัน โดยมีสองตัวเลขในวงเล็บ — ไม่ใช่ระหว่างกัน
OUTPUT DIV(17, 5) // → 3
English
MOD: the remainder
MOD(a, b)gives the remainder after dividing.MOD(17, 5)is2. A number is even whenMOD(N, 2) = 0.
ไทย
MOD: เศษ
MOD(a, b)ให้เศษหลังจากทำการหารMOD(17, 5)คือ2. จำนวนเป็นเลขคู่เมื่อMOD(N, 2) = 0
OUTPUT MOD(17, 5) // → 2
English
Watch out
DIVandMODwork on whole numbers; plain/gives a decimal.- Together they "undo" a division:
DIV(17, 5) * 5 + MOD(17, 5)=17.
ไทย
ระวัง
DIVและMODทำงานกับจำนวนเต็ม; การหารธรรมดา/ให้ผลทศนิยม- รวมกันแล้วทำให้ "ยกเลิก" การหาร:
DIV(17, 5) * 5 + MOD(17, 5)=17
English
Common mistakes
DIV(a, b)is whole-number division;MOD(a, b)is the remainder. Both are written with brackets.- Use brackets to control the order of arithmetic.
ไทย
ข้อผิดพลาดที่พบบ่อย
DIV(a, b)คือการหารจำนวนเต็ม;MOD(a, b)คือเศษ ทั้งสองเขียนด้วยวงเล็บ- ใช้วงเล็บเพื่อควบคุมลำดับการคำนวณทางคณิตศาสตร์
English
Now you try
- Use
+ - * / ^, and the functionsDIV(a, b)/MOD(a, b). - Press Check answer to test it.
ไทย
ลองดูเลย
- ใช้
+ - * / ^และฟังก์ชันDIV(a, b)/MOD(a, b) - กด Check answer เพื่อทดสอบ
Output 6 times 7 (the answer is 42). · แสดงผล 6 คูณ 7 (คำตอบคือ 42)
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
Use DIV(20, 3) to output how many whole times 3 goes into 20 (the answer is 6). · ใช้ DIV(20, 3) เพื่อแสดงจำนวนครั้งเต็มที่ 3 เข้าไปใน 20 (คำตอบคือ 6)
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
Use MOD(23, 5) to output the remainder when 23 is divided by 5 (the answer is 3). · ใช้ MOD(23, 5) เพื่อแสดง เศษ เมื่อ 23 หารด้วย 5 (คำตอบคือ 3)
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
Use ^ to output 2 to the power of 10 (the answer is 1024). · ใช้ ^ เพื่อแสดง 2 ยกกำลัง 10 (คำตอบคือ 1024)
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่