The for Loop C++ | Sololearn: Learn to code for FREE!

+1

The for Loop C++

for (int a = 0; a < 10; a++) { cout << a << endl; } The output of this code prints out a range of numbers from 0 till 9 in a vertical syntax, my question is can we or is it possible to output the range in a horizontal syntax i.e // 0 1 2 3 4...9 unlike it been vertical i.e /* 0 if yes kindly someone show me how to please? 1 2 . 9 */

7/9/2020 5:32:06 AM

Simangolwa Lifwatila

5 Answers

New Answer

+7

Your answer is in the question itself.. try by removing endl as explained by 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥

+4

Simangolwa Lifwatila use cout << a<< " "; instead of cout << a << endl;. "endl" is the constant for a linebreak, thus ... << endl; results in a new line. https://code.sololearn.com/cBMElC6J5ayV/?ref=app

+4

Code: cout<<a<<" "; Instead of: cout<<a<<endl; (Space b/w double quotation marks )

+3

Thanks for the help!

+2