What is the value of X after X ← 3 + MOD(20, 6) * 2 ^ 2 ?
- MOD(20, 6): 20 ÷ 6 = 3 remainder 2, so MOD(20, 6) = 2.
- Power next: 2 ^ 2 = 4.
- Multiply before adding: 2 * 4 = 8.
- Add: 3 + 8 = 11.
Answer: X = 11
Computer Science · Programming. The idea in plain words, the rules to remember, the mistake to avoid and a worked example, written and checked by Mega Lecture.
A program stores data in named memory locations. A variable holds a value that can change while the program runs. A constant holds a value that is set once and stays fixed. Each one has an identifier (its name) and a data type that says what kind of value it holds.
Choose the data type from how the data is used. Numbers used in calculations are INTEGER or REAL. Anything that is not calculated with, such as a phone number, is a STRING.
Data comes in with INPUT and goes out with OUTPUT. Operators then work on the values: arithmetic operators calculate, relational operators compare, and logical operators join conditions.
Many students work from left to right and forget that * and / are done before + and −. They also mix up DIV (the whole-number quotient) and MOD (the remainder).
Answer: X = 11
Type what you are stuck on. The helper finds the explanation, worked examples and the notes to read, free and instant.
← Trace tables and correcting algorithmsSequence, selection, iteration and string handling →Take a Computer Science test