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
#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:
