Help me with this pattern. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Help me with this pattern.

so i need a step by step explanstion for this code thanks #include "iostream" using nanespace std; int main (){ int a,b; for(a=1;a<=5;a++){ for(b=1;b<=a;b++){ cout<<b; } cout<<endl; } } Output 1 12 123 1234 12345

20th Aug 2016, 1:10 AM
Suhail Pappu
Suhail Pappu - avatar
2 Answers
+ 2
1st iteration a=1 and b=1 print 1 then b increase once, condition fails in 2nd loop,it moves to first loop. increment the value of a by 2. 2nd iteration initial a=2 and b=1 print 1 b++ => now b=2 again condition true print 2 b++ now b=3 a!=b condition false, moves to first loop. 3rd iteration intial a=3 and b=1 it follows the same steps in 2nd iteration. and print 123 same steps for a=4 and a=5. in a=6, condition false ,so it terminate
20th Aug 2016, 4:25 AM
Muhammed cp
Muhammed cp - avatar
+ 1
thx muhammed
20th Aug 2016, 11:10 AM
Suhail Pappu
Suhail Pappu - avatar