Ask Question

What is the output of the following code segment?

n = 1;

for (; n < = 5; )

cout << n << ' ';

n++;

1. 1 2 3 4 5

2. 1 1 1 ... and on forever

3. 2 3 4 5 6

4. 1 2 3 4

5. 2 3 4 5

+5
Answers (1)
  1. 21 March, 04:48
    0
    Answer

    1 2 3 4 5

    Explanation:

    initialize the value of n with 1

    then, for loop is executed until the condition is true.

    so, it check the condition 1<=5, condition true, code is executed and print 1

    and n become 2.

    again check condition 2<=5 condition true, code is executed and print 2

    and n become 3.

    and so on ...

    it print 1 2 3 4 5 after that check condition 6<=5 condition false, it terminate from loop.

    Therefore, the answer is 1 2 3 4 5
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What is the output of the following code segment? n = 1; for (; n < = 5; ) cout ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers