what is the code for printing even number of rows?
Manmohan loves patter
Hey @Sejal.Aloria
the pattern is like this:
1
11
111
1001
11111
100001
so basically if n is given you’ve to print n rows (from 1st row to nth), here n = 6 in this example, so you’ve to print row 1 to row 6 here.
Now if the row no you’re printing is odd( which ,means i%2!=0), you print same no of ones as the row no, like for the 3rd row, print 3 ones, for row 5, print 5 ones,
Otherwise if the row no you’re printing is even, which means(i%2 == 0), you print one, then i-2 zeroes, then again print 1. like for the 4th row, you print 1, then 2 zeroes then 1 again,
similarly for row 6, you print one 1, four zeroes and a 1 again.
I am not getting correct output. can you send me the code for this.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.