-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC9PatternPrint0_1Pattern.cpp
More file actions
50 lines (46 loc) · 1.03 KB
/
C9PatternPrint0_1Pattern.cpp
File metadata and controls
50 lines (46 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
using namespace std;
int main(){
// 0-1 Pattern
int n;
cout<<"N : ";
cin>>n;
bool b = 1;
for(int i = 1; i<=n; i++){
for(int j = 1 ; j<=i; j++){
cout<<" ";
if(i%2!=0){
if(j%2!=0){
cout<<b;
}
else{
cout<<!b;
}
}
else{
if(j%2==0){
cout<<b;
}
else{
cout<<!b;
}
}
}
cout<<endl;
}
// Secound Metheod
cout<<"\n\n";
for(int i = 1; i<=n; i++){
for(int j = 1 ; j<=i; j++){
// by diagraam we see thant 1 is one the place when row_nu + col_num == even else 0
if((i+j)%2==0){
cout<<" 1 ";
}
else{
cout<<" 0 ";
}
}
cout<<endl;
}
return 0;
}