Arithmetic, DIV and MOD · Aritmética, DIV e MOD
Arithmetic operators
- Pseudocode uses
+-*/and^for the usual maths. /gives a real answer (with a decimal point).
Operadores aritméticos
- Pseudocódigo usa
+-*/e^para matemática comum. /dá uma resposta real (com ponto decimal).
OUTPUT 6 + 2 // → 8
OUTPUT 6 * 2 // → 12
OUTPUT 7 / 2 // → 3.5
^ 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/.
^ eleva a uma potência
^significa "à potência de".2 ^ 10é 2 multiplicado por si mesmo dez vezes, o que resulta em1024.- O programa lista isso ao lado de
+,-,*e/.
OUTPUT 2 ^ 10 // → 1024
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: divisão de número inteiro
DIV(a, b)divide e descarta o resto.DIV(17, 5)é3— 5 cabe em 17 três vezes inteiras.- É escrito como uma função, com os dois números entre parênteses — não entre eles.
OUTPUT DIV(17, 5) // → 3
MOD: the remainder
MOD(a, b)gives the remainder after dividing.MOD(17, 5)is2. A number is even whenMOD(N, 2) = 0.
MOD: o resto
MOD(a, b)dá o resto após a divisão.MOD(17, 5)é2. Um número é par quandoMOD(N, 2) = 0.
OUTPUT MOD(17, 5) // → 2
Watch out
DIVandMODwork on whole numbers; plain/gives a decimal.- Together they "undo" a division:
DIV(17, 5) * 5 + MOD(17, 5)=17.
Atenção
DIVeMODfuncionam com números inteiros; plain/dá decimal.- Juntos eles "desfazem" uma divisão:
DIV(17, 5) * 5 + MOD(17, 5)=17.
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.
Erros comuns
DIV(a, b)é divisão de número inteiro;MOD(a, b)é o resto. Ambos são escritos com parênteses.- Use parênteses para controlar a ordem das operações aritméticas.
Now you try
- Use
+ - * / ^, and the functionsDIV(a, b)/MOD(a, b). - Press Check answer to test it.
Agora você tenta
- Use
+ - * / ^, e as funçõesDIV(a, b)/MOD(a, b). - Pressione Check answer para testá-lo.
Output · Saída 6 times 7 (the answer is 42). · Saia 6 vezes 7 (a resposta é 42).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Use DIV(20, 3) to output how many whole times 3 goes into 20 (the answer is 6). · Use DIV(20, 3) para saia quantas vezes inteiras 3 cabe em 20 (a resposta é 6).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Use MOD(23, 5) to output the remainder when 23 is divided by 5 (the answer is 3). · Use MOD(23, 5) para saia o resto quando 23 é dividido por 5 (a resposta é 3).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Use ^ to output 2 to the power of 10 (the answer is 1024). · Use ^ para saia 2 elevado à potência de 10 (a resposta é 1024).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.