In this tutorial, we will write a program in C to display the diagonal star pattern. So you may go through the following topic in C.
Diagonal Star Pattern in C
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 | #include <stdio.h> int main() { int i, j, rows; printf("Enter the no. of rows: "); scanf("%d", &rows); int m = (2 *rows) - 1; for (i = 1; i <= m; i++) { for (j = 1; j <= m; j++) { if (i == j || j == (m - i + 1)) printf("*"); else printf(" "); } printf("\n"); } return 0; } |
Output: