levo

Fundamentals of Programming

Arithmetic operations

  • 3 things to know
  • Paper 1

Overview

Recall questions on real division against integer division, DIV and MOD, the type each operation returns, and the packing problems the remainder is used to solve.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Process

Which arithmetic operations does a program need, and how do they group?

Process

What is 17 MOD 5, and how do the quotient and remainder relate back to the original number?

Key term

What does rounding do? Give the results of rounding 4.6 and 4.4 to the nearest whole number, and 3.14159 to two decimal places.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Which arithmetic operations does a program need, and how do they group?

    Model answer

    Four are the ordinary operations of arithmetic: adding, subtracting, multiplying and dividing. Division splits into two, because a computer must be told which kind is wanted — real division gives a fractional result, while integer division discards the fraction and leaves a separate remainder alongside the quotient. Raising to a power is the fifth operation. The last two do not calculate at all but control precision: rounding adjusts a value to the nearest step, while truncation simply cuts the unwanted digits away, which is why the two disagree on a value such as −3.7.

  2. 2

    What type of result do addition, subtraction and multiplication give?

    Model answer

    Applied to two integers each gives an exact integer result. If either operand is a real, the result is a real. Multiplication and addition of large integers can overflow if the result will not fit in the storage allowed for the type.

  3. 3

    What does real (float) division give, and what is 7 / 2?

    Model answer

    It gives the full quotient including any fractional part, so 7 / 2 = 3.5. The result is a real even when it happens to have no fractional part, so 6 / 3 gives 3.0 rather than the integer 3 in most languages.

  4. 4

    What does integer division give, and what is 17 DIV 5?

    Model answer

    It gives only the whole number of times the divisor goes into the dividend, discarding any fractional part, so 17 DIV 5 = 3.

  5. 5

    What is 17 MOD 5, and how do the quotient and remainder relate back to the original number?

    Model answer

    17 MOD 5 = 2. The remainder is what is left over after the whole divisions, so divisor x quotient + remainder returns the original: 5 × 3 + 2 = 17. When the operands are positive the remainder is always at least 0 and less than the divisor.

  6. 6

    Contrast integer division with real division using 22 and 7.

    Model answer

    Real division gives 22 / 7 = 3.142857..., a real value with a fractional part. Integer division gives 22 DIV 7 = 3 with 22 MOD 7 = 1, two exact whole numbers. Real division answers how much each share is worth; integer division answers how many whole shares there are and what is left over.

Other ways to work this

The same content, four other ways.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A driver is .
softwarehardwarestorage

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AThe integer 5 is 0101.
B0.75 is 1/2 + 1/4.
CThe fraction bits are 1100.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

Head means the first single element of a non-empty list.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Fundamentals of Programming, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.