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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #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
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *