Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2
for (int i = 0;i <= 9; i++) { for (int d = 10 - i; d > 0;d--) { cout<<"\t"; } for (int j = 1; j <= i; j++) { cout<<"\t"<<i<<"\t" ; } cout<<"\n"; } when i=0, 1st nested loop continues 10 times and so it gives 10 tab spaces. in the 2nd nested loop j=1 and i=0 so loop not works. i=1 and 1st nested loop continues 9 times and so it gives 9 tab spaces. In the 2nd nested loop j=1 and i=1 so the loop continues 1 times and it prints 1 tab space then 1 and then 1 tab spaces. i=2 and 1st nested loop continues 8 times and so it gives 8 tab spaces. In the 2nd nested loop j=1 and i=2 so the loop continues 2 times and it prints 1 tab space then 2 and then 1 tab spaces and again 1 tab space and then 2 and 1 tab space. i=3 and 1st nested loop continues 7 times and so it gives 7 tab spaces. In the 2nd nested loop j=1 and i=3 so the loop continues 3 times and it prints 3, 3 times where the difference between these numbers are two tab spaces. This continues....... when i=9, 1st nested loop continues 1 times and so it gives 1 tab spaces. In the second nested loop j=1 and i=9 so the loop continues 9 times and it prints 9 9 times where the difference between these numbers are two tab spaces. And then the loop stop . Hope this helps.
13th Apr 2021, 6:32 AM
The future is now thanks to science
The future is now thanks to science - avatar