Manmohan Loves Patterns - I

Given N, help Manmohan to print pattern upto N lines. For eg For N=6 , following pattern will be printed.

1
11
111
1001
11111

100001

Input Format:
Single number N.

Constraints:
N<=1000

Output Format
Pattern corresponding to N.

Sample Input
6
Sample Output
1
11
111
1001
11111
100001
sir in this question, i am not able to find the logic used in the pattern. if it is in binary form then it is 1,3,7… but it should have 101 which is 5 to make any pattern

@Sheenagoyal21 The logic is simple. When the column position is 0 ie. j==0 and also when j==i (ie. the diagonal element) you will always have to print 1.
In other Cases when j!=0 , you will have to check if i%2==0(ie. even positioned row) . If it is an even positioned row, you will have to print 1, else print 0.

When input is 6:
1 ----> since j==0
11 —> since j==0, j==i
111 —> since j==0, i%2==0, j==i
1001 —> since j==0, i%2!=0, i%2!=0, j==i
11111
100001
and so on.

Hope this helps :slightly_smiling_face:

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.