In this tutorial, we will write a C program to print a square star pattern. Before that, you may go through the following topics in C.
Square Star pattern in C
The program takes the user input for the number of rows and uses that in a for loop.
#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter the no. of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= rows; j++)
printf("* ");
printf("\n");
}
return 0;
}
Output:
Enter the no. of rows: 5
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *