C_Patterns_Examples
C_Patterns_Examples
13. X Pattern
-------------
void xPattern() {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (j == i || j == n - i + 1) printf("*");
else printf(" ");
}
printf("\n");
}
}
Output:
* *
* *
*
* *
* *
14. Z Pattern
-------------
void zPattern() {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == 1 || i == n || j == n - i + 1) printf("*");
else printf(" ");
}
printf("\n");
}
}
Output:
*****
*
*
*
*****