0

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 */

9th Jul 2020, 5:32 AM
Simangolwa Lifwatila
Simangolwa Lifwatila - avatar
5 Answers
+ 7
Your answer is in the question itself.. try by removing endl as explained by 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥
9th Jul 2020, 5:47 AM
Aditya
Aditya - avatar
+ 4
Code: cout<<a<<" "; Instead of: cout<<a<<endl; (Space b/w double quotation marks )
9th Jul 2020, 9:09 AM
PeabrainGuy
PeabrainGuy - avatar
+ 3
Thanks for the help!
9th Jul 2020, 1:16 PM
Simangolwa Lifwatila
Simangolwa Lifwatila - avatar