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.

City Guilds Model Questions Vol1 2021 Information Technology Objective / Multiple Choice Hard Difficulty
Question 4 CITY_GUILDS_MODEL_QUESTIONS_VOL1 • 2021 • INFORMATION_TECHNOLOGY • objective

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

A. Buggy output: 2; Correct output: 120; Time complexity: O(n log n)
Correct Answer B. Buggy output: 2; Correct output: 102; Time complexity: O(n log n)
C. Buggy output: 12; Correct output: 102; Time complexity: O(n log n)
D. Buggy output: 2; Correct output: 102; Time complexity: O(n^2)
Correct Answer
B
Correct Option:
Buggy output: 2; Correct output: 102; Time complexity: O(n log n)

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.

Unlock Full Access Available for Android & Windows
Chat with Support