HomeInterview QuestionsPrint numbers from 1 to 5.

Print numbers from 1 to 5.

🟢 Easy Coding Fresher level
1Times asked
Apr 2026Last seen
Apr 2026First seen

💡 Model Answer

To print numbers from 1 to 5, you can use a simple for-loop that iterates over the range of numbers. In Python, the range function generates a sequence of integers, and you can start at 1 and end at 5 inclusive by using range(1, 6). Inside the loop, you print each number. The algorithm runs in O(n) time, where n is the count of numbers to print (in this case, 5). It also uses O(1) additional space. Example code:

for i in range(1, 6):

print(i)

This will output:

1

2

3

4

5

The same logic applies to other languages: use a for-loop with an index starting at 1 and incrementing until it reaches 5. The key concepts are understanding loop boundaries and the inclusive/exclusive nature of the end value in the chosen language.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500