0
End line loop in C++?
How to use muLtiple end line in while loop?
7 Antworten
+ 1
int num=0;
while(num<50)
{
cout<<num<<" ";
num++;
if(num%5==0)
cout<<endl;
}
+ 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;
}
+ 1
Question is not clear ..
Atleast to me.. Elaborate more pls..
edit:
while( condition) {
//...
cout<<endl<<endl<<endl;
cout<<endl;
//...
}
???
+ 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
+ 1
check on each iteration if the current number is a multiple of 5 – if so endl
0
int num=0,n;
cin>>n;
while (num<n){
cout<<endl;
num++;
}
value of n is enter by user
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.