Arithmetic, DIV and MOD · Aritmética, DIV y MOD
Arithmetic operators
- Pseudocode uses
+-*/and^for the usual maths. /gives a real answer (with a decimal point).
Operadores aritméticos
- El pseudocódigo utiliza
+,-,*,/y^para las operaciones matemáticas habituales. /da una respuesta real (con punto 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 una potencia
^significa "elevado a la potencia de".2 ^ 10es 2 multiplicado por sí mismo diez veces, lo cual es1024.- El programa curricular lo enumera junto con
+,-,*y/.
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: división de números enteros
DIV(a, b)divide y descarta el resto.DIV(17, 5)es3— 5 cabe en 17 tres veces exactas.- Se escribe como una función, con los dos números entre corchetes, no separados por él.
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: el resto
MOD(a, b)da el resto tras dividir.MOD(17, 5)es2. Un número es par cuandoMOD(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.
Tenga cuidado
DIVyMODfuncionan con números enteros; la simple/da un decimal.- Juntos "deshacen" una división:
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.
Errores comunes
DIV(a, b)es la división de números enteros;MOD(a, b)es el resto. Ambos se escriben entre corchetes.- Usa corchetes para controlar el orden de las operaciones aritméticas.
Now you try
- Use
+ - * / ^, and the functionsDIV(a, b)/MOD(a, b). - Press Check answer to test it.
Ahora tú prueban
- Usa
+ - * / ^, y las funcionesDIV(a, b)/MOD(a, b). - Presiona Check answer para probarlo.
Output · Salida 6 times 7 (the answer is 42). · Escribe 6 veces 7 (la respuesta es 42).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Use DIV(20, 3) to output how many whole times 3 goes into 20 (the answer is 6). · Usa DIV(20, 3) para escribir cuántas veces enteras cabe 3 en 20 (la respuesta es 6).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Use MOD(23, 5) to output the remainder when 23 is divided by 5 (the answer is 3). · Usa MOD(23, 5) para escribir el residuo cuando se divide 23 entre 5 (la respuesta es 3).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Use ^ to output 2 to the power of 10 (the answer is 1024). · Usa ^ para escribir 2 elevado a la potencia de 10 (la respuesta es 1024).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.