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).
中文
算术运算符
- 伪代码用
+-*/和^做常见的数学运算。 /给出一个实数结果(带小数点)。
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做除法,并丢掉余数。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给出相除之后的余数。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是整除;MOD是余数。- 用括号控制运算顺序。
English
Now you try
- Use
+ - * / ^, and the functionsDIV(a, b)/MOD(a, b). - Press Check answer to test it.
中文
现在轮到你
- 使用
+ - * / ^,以及DIV/MOD。 - 按检查答案来测试它。
Output · 输出 6 times 7 (the answer is 42). · 输出 6 乘以 7(答案是 42)。
Click Run to see the output here. · 点击“运行”查看此处输出。
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. · 点击“运行”查看此处输出。
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. · 点击“运行”查看此处输出。
Use ^ to output 2 to the power of 10 (the answer is 1024). · 用 ^ 输出 2 的 10 次方(答案是 1024)。
Click Run to see the output here. · 点击“运行”查看此处输出。