1
0 1
0 1 0
1 0 1 0
1 0 1 0 1
0 1 0 1 0 1
this is the pattern to be printed
I tried using various methods but I could not get the exact pattern
PS:i am a beginner at programming
#include <stdio.h>
void print_pattern(int n) {
for (int i = 1; i <= n; i++) {
int start;
if (i % 2 == 0) {
start = 0;
} else {
start = 1;
}
for (int j = 0; j < i; j++) {
printf("%dt", (start + j) % 2);
}
printf("n");
}
}
int main() {
int n = 6;
print_pattern(n);
return 0;
}
New contributor
ALLEN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.