0

End line loop in C++?

How to use muLtiple end line in while loop?

6th Dec 2021, 3:44 PM
Abdul Basit Khan
Abdul Basit Khan - avatar
7 ответов
+ 1
int num=0; while(num<50) { cout<<num<<" "; num++; if(num%5==0) cout<<endl; }
6th Dec 2021, 3:58 PM
Jayakrishna 🇮🇳
+ 2
Basit ALp Int i=0,j=0,num=0; While(i<10){ While(j<5){ cout<<num++<<" "; j++;} cout<<endl; j=0; i++;} Instruction: i=0 & j=0 & num=0 -> Enters first loop(i<10):true; (which is for each new line) -> Enters 2nd Loop(j<5):true; (which is for each 5 ints in a line) -> cout num++(repeats 5 time/each time num increases by one) -> terminates 2nd loop -> cout endl(new line) -> j=0 (to start over the new line's 5 ints) -> i++ -> back to first of the First loop again -> Check condition (i<10):True -> start over Again! Hopes be useful Ask your doubts Ya Ali Jayakrishna🇮🇳 check it! its urs but one line lesser int num=0; while(num<50) { cout<<num++<<" "; if(num%5==0) cout<<endl; }
6th Dec 2021, 10:22 PM
‎میم شین‎
+ 1
Question is not clear .. Atleast to me.. Elaborate more pls.. edit: while( condition) { //... cout<<endl<<endl<<endl; cout<<endl; //... } ???
6th Dec 2021, 3:49 PM
Jayakrishna 🇮🇳
+ 1
in c++ if i want to write a program to display numbers from 0 to 50 and i want to write it in Loop(while) now i want to Cout end Line after every five numbers then how can i write this code??? i,e 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
6th Dec 2021, 3:53 PM
Abdul Basit Khan
Abdul Basit Khan - avatar
+ 1
check on each iteration if the current number is a multiple of 5 – if so endl
6th Dec 2021, 3:58 PM
Lisa
Lisa - avatar
0
int num=0,n; cin>>n; while (num<n){ cout<<endl; num++; } value of n is enter by user
8th Dec 2021, 4:55 AM
Simi Jain
0
‎میم شین‎ yes. I checked it before also. But I am not sure about OP completed lesson of pre/post increment. So I added in line by line detaily.. If you use for loop then it's just 2 lines of code.. You can try that now.
8th Dec 2021, 11:17 AM
Jayakrishna 🇮🇳