Manmohan loves pattern 1

what should i do to get this pattern
i wrote this code to give this o/p
[8:41 PM, 9/14/2019] :rofl::rofl::rofl:: #include
using namespace std;
int main() {
int n,i=1,val=1;
cin>>n;
while(i<=n){
int j=1;
while(j<=i){
cout<<val;
j=j+1;
}
cout<<endl;
i=i+1;
}
return 0;

}
[8:41 PM, 9/14/2019] :rofl::rofl::rofl:: 1
11
111
1111
11111
111111
help me to get the o/p as
1
11
111
1001
11111
100001

@rastogi.g1998 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: