C program to print square star pattern

  • Write a program in C to print square star (*) pattern of n rows using for loop.
  • Write a C program to print a square pattern of star (*) character using loop.
For a square star pattern of side 5 stars. Program's output should be:

Required Knowledge

Algorithm to print square star pattern using loop
  • Take the number of stars in each side of square as input from user using scanf function. Let it be N.
  • We will use two for loops to print square star pattern.
    • In one iteration, outer for loop will print one row of pattern.
    • In one iteration, inner for loop will print one star (*) characters in a row.

C program to print square star pattern


int main(){
    int side, i, j;
    printf("Enter side of square\n");
    scanf("%d", &side);
    /* Row iterator for loop */
    for(i = 0; i < side; i++){
     /* Column iterator for loop */
        for(j = 0; j < side; j++){
    return 0;
Enter side of square

Related Topics
C program hollow square pattern
C program rectangle star pattern
C program hollow rectangle pattern
C program rhombus star pattern
C program diamond star pattern
C program binary triangle pattern
C program heart shape star pattern
C program palindrome triangle pattern
C program hollow diamond star pattern
List of all C pattern programs