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?
- A.
Read number n and print the integers counting up to (n-1)
- B.
Read number n and print the integers counting up to i
- C.
Read number n and print the integers counting up to (n+1)
- 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).