HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Problems
  2. /This pseudocode works on a whole number that is input…
HardComputer ScienceHigh School (9–10)Computer Science › ProgrammingNumericalIGCSE

This pseudocode works on a whole number that is input…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

This pseudocode works on a whole number that is input.

pseudocode
DECLARE Number : INTEGER
DECLARE Sum : INTEGER
Sum ← 0
INPUT Number
WHILE Number > 0 DO
    Sum ← Sum + MOD(Number, 10)
    Number ← DIV(Number, 10)
ENDWHILE
OUTPUT Sum

Complete a trace table for the input 4083, with the columns Number and Sum. How many times does the loop run, and what is output? What does the program do, in one sentence?

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

FOR Count ← A TO B STEP S ... NEXT Count runs a known number of times. WHILE <condition> DO ... ENDWHILE tests first and may run no times. REPEAT ... UNTIL <condition> tests last and runs at least once. A total adds each value; a count adds 1. A trace table records every variable and output at each step.

The worked solution

Have you tried it?

Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.

The trace table. The first row is the input, then one row for each pass.

  • Number 4083, Sum 0
  • Number 408, Sum 3
  • Number 40, Sum 11
  • Number 4, Sum 11
  • Number 0, Sum 15

Count. The loop ran 4 times, once for each digit. The output is 15.

What it does. It adds up the digits of the number: 4+0+8+3=154 + 0 + 8 + 3 = 154+0+8+3=15.

Check. The digit 0 adds nothing, so Sum stays 11 in the third pass. That is a good place to check your own table.

Watch out. A WHILE loop tests first. For the input 0 it runs no times and outputs 0, which is the right digit sum.

Log in to save this for later
← All Problems
← A box office sells from 1 to 6 tickets to one person…A long scenario question. At a sports day, six runners each run 100 metres… →
More onComputer Science › Programming

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Loops, totals, counts and nested statementsVariables, Selection and Loops in Pseudocode

More on this topic

  1. A long scenario question. A teacher has the names of 5 students in the file Names.txt, one name a…Hard
  2. Shopping.txt holds six lines: bread, rice, milk, eggs, tea and jam…Medium
  3. The file Best.txt holds one line: 120. What is output, and what does Best.txt hold afterwards, when…Easy
The nine squares of a board are input row by row: X, O, O, then X, X, X, then O, a dot for an empty…Hard
  • Three teams play three games each. Points[Team, Game] holds the points of a team in a game…Medium
  • All problems on this topic →