Print a Hollow square star pattern
#include <stdio.h>
int main()
{
int i, j, N;
printf("Enter number of rows: ");
scanf("%d", &N);
/* Iterate over each row */
for (i = 1; i <= N; i++)
{
/* Iterate over each column */
for (j = 1; j <= N; j++)
{
if (i == 1 || i == N || j == 1 || j == N)
{
/* Print star for 1st, Nth row and column */
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
Output
Enter number of rows : 5
*****
* *
* *
* *
*****
0 Comments