+ 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
2 Antworten
+ 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
+ 1
thx muhammed