City Guilds Model Questions Vol1 2021 Information Technology Question 4
Practice objective / multiple choice question 4 from the 2021 City Guilds Model Questions Vol1 Information Technology examination.
Consider the following pseudocode that is intended to compute the sum of the digits of all integers from 1 to \(n\).\n\n``` sum = 0\nfor i = 1 to n\n digit_sum = 0\n num = i\n while num > 0\n digit_sum = digit_sum + (num mod 10)\n num = num // 10\n end while\n sum = digit_sum // <-- possible error line\nend for\nprint sum\n```\n\n(a) What output does the program produce when \(n = 20\)?\n(b) Identify the logical error and give the corrected line of code.\n(c) With the correction, what is the correct output for \(n = 20\)?\n(d) State the time‑complexity of the algorithm in Big‑O notation (as a function of \(n\)).
Answer Options
About This Question
This is City Guilds Model Questions Vol1 2021 Information Technology Question 4. It is one of the objective questions from the 2021 City Guilds Model Questions Vol1 Information Technology examination.
Difficulty level: Hard .
Master the Exam!
You've seen a preview, but there are thousands more questions plus AI tutor to break down complex solutions.