+ 3

Print pattern

How to print this pattern when the input is 5 0 1 1 1 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 1 0 1 1 1 0 If u look closely, its printing a C using "1".

23rd Feb 2018, 1:50 PM
Alind
Alind - avatar
2 Antworten
+ 4
Not so efficient but it works: #include <stdio.h> int main() { int r; printf("Enter number of rows for the pattern: "); scanf("%d", &r); printf("%d\n\n", r); int l = r - 1, c, b, x, y ; for(y = 0; y < r; y++) { c = y && y < l ? 1 : 0; b = c ? 0 : 1; for(x = 0; x < r; x++) { if(x && x < l) printf("%d",b); else { if(y > 1 && y < l - 1 && x == l) printf("%d",b); else printf("%d",c); } if(x < l) printf(" "); } printf("\n"); } return 0; } Hth, cmiiw
24th Feb 2018, 8:27 PM
Ipang