+ 3

Plz help!

I am confused in this code I couldn't understand the code https://code.sololearn.com/cGMg25kTUKh6/?ref=app

3rd Oct 2017, 6:48 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
7 Respostas
+ 3
First loop is used to print new line, so as to maintain pattern Second loop prints corresponding no. of stars to create a triangle think it as a 4×4 grid first loop is used for rows second loop is used for columns Consider: (place cout<<"\n" after second loop) when i=1, i.e. 1st row j=1, i.e. 1 row & 1 star when i=2, i.e. 2nd row j=1,2 i.e. 2 rows & 2 stars when i=3, i.e. 3rd row j=1,2,3 i.e. 3 rows & 3 stars when i=4, i.e. 4th row j=1,2,3,4 i.e. 4 rows & 4 stars "j" will print a star in the specified columns in the row defined by "i"
3rd Oct 2017, 7:05 PM
Ankit Agrawal
Ankit Agrawal - avatar
+ 2
because you are reassigning 1 to "j" in the for loop itself, that's what is making it 1 for each unique value of "i" for(int j=1 <--this is initializing j with 1
3rd Oct 2017, 7:37 PM
Ankit Agrawal
Ankit Agrawal - avatar
+ 2
you are not exiting from first loop until i<5 second loop gets executed for every iteration of outer loop
3rd Oct 2017, 7:42 PM
Ankit Agrawal
Ankit Agrawal - avatar
+ 2
ohhhhhhh!!!!! thnk u very much !!!
3rd Oct 2017, 7:44 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
+ 1
yeah ! but after the 1st loop (outer and inner both completed) the value of j suldn't be 2? why it is starting again from 1 in the 2nd time
3rd Oct 2017, 7:11 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
+ 1
then why not I is starting from 1 again??
3rd Oct 2017, 7:39 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
+ 1
I mean 'i' which I assigned =1 in the outer loop
3rd Oct 2017, 7:40 PM
Saurabh Tiwari
Saurabh Tiwari - avatar