Start Read n Initialize i to 1. while i < n do: Write i Increment i end while…

2018

Start Read n Initialize i to 1. while i < n do: Write i Increment i end while Stop.

Which of the following options is CORRECT?

  1. A.

    Read number n and print the integers counting up to (n-1)

  2. B.

    Read number n and print the integers counting up to i

  3. C.

    Read number n and print the integers counting up to (n+1)

  4. D.

    Read number n and print the integers counting up to n

Attempted by 157 students.

Show answer & explanation

Correct answer: A

The correct option is A. The algorithm initializes i = 1 and runs a loop while i < n. Since the loop terminates when i reaches n, the last value printed is n-1. Therefore, it reads n and prints integers counting from 1 up to (n-1).

Explore the full course: Btsc Lab Assistant