Arithmetic, DIV and MOD
Cambridge Pseudocode Lesson 4 2:05 English narration · English + 中文 subtitles burned in
Chapters
Transcript
Plus, minus, times and slash behave exactly as you would expect, and there is nothing to memorise about the first three.
加、减、乘、除的行为完全符合你的预期, 前三个没有什么要背的。
The fourth is worth a second look.
第四个值得再看一眼。
Seven divided by two is three point five — a slash always produces a REAL answer, with a decimal point, even when the division comes out exactly.
7 除以 2 是 3.5—— 斜杠总是给出一个 REAL 类型的答案,带小数点, 哪怕除得正好也一样。
That is precisely why the next two operators exist.
而这正是接下来那两个运算符存在的原因。
Here is seventeen of something.
这里有 17 个东西。
Now share them out in fives.
现在按 5 个一份分出去。
You get three whole groups — and then you run out: two are left over, because a fourth group would need five and there are only two.
你得到 3 个完整的份——然后就不够了: 剩下 2 个,因为第 4 份需要 5 个,而这里只有 2 个。
Both answers are now on the screen, and DIV and MOD are simply the names for them.
两个答案现在都在屏幕上了, 而 DIV 和 MOD 只不过是它们的名字。
Written down: seventeen DIV five is three, the number of whole groups.
写出来就是:17 DIV 5 等于 3,也就是完整份数。
Seventeen MOD five is two, the leftover.
17 MOD 5 等于 2,也就是剩下的。
And a plain slash gives three point four, which is neither of those and is why you cannot use it here.
而一个普通的斜杠给出 3.4,那两者都不是, 这也是为什么在这里不能用它。
Put them back together and nothing has been lost — three groups of five, plus the two spare, is seventeen again.
把它们再拼回去,什么也没丢—— 3 份 5 个,再加上多出来的 2 个,又是 17。
One use of MOD comes up on paper after paper, so learn it as a phrase.
MOD 的一种用法在一份又一份考卷里出现,所以把它当成一个短语记住。
A number is even exactly when dividing it by two leaves nothing left over.
一个数是偶数,恰好就是当它除以 2 什么都不剩的时候。
Eight MOD two is nought, so eight is even.
8 MOD 2 是 0,所以 8 是偶数。
Nine MOD two is one, so nine is odd.
9 MOD 2 是 1,所以 9 是奇数。
Wrap that in an IF and you have the standard even-or-odd answer.
把它包进一个 IF 里,你就得到了标准的奇偶判断答案。
Four things to take with you.
带走四点。
One: plain division gives a REAL answer with decimals.
第一:普通的除法给出带小数的 REAL 答案。
Two: DIV counts how many whole times one number goes into another.
第二:DIV 数的是一个数能整整装进另一个数几次。
Three: MOD gives what is left over.
第三:MOD 给出剩下的部分。
Four: N MOD 2 equal to nought means N is even.
第四:N MOD 2 等于 0 表示 N 是偶数。
Now do the three tasks.
现在去做那三道题。