# C program to print square star pattern

Here is a C program to print square star pattern of n rows using for 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.

Here is the matrix representation of the square star pattern. The row numbers are represented by i whereas column numbers are represented by j.

## C program to print square star pattern

```#include<stdio.h>

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++){
printf("*");
}
printf("\n");
}
return 0;
}
```
Output
```Enter side of square
5
*****
*****
*****
*****
*****
```

## Importance of Practicing Square Star Pattern Printing Programs for Beginners

• Understanding Looping and Conditional Statements : The square star pattern printing program helps beginners understand the concept of nested loops. By using nested loops to print rows and columns of stars, beginners learn how to control the flow of execution in a program using loops and conditional statements.

• Enhances Problem-solving Skills : Writing a square star pattern printing program involves breaking down a complex pattern into smaller, manageable parts. This process enhances problem-solving skills as beginners learn to analyze the pattern and devise a plan to print it using loops and conditional statements.

• Improves Debugging Skills : Debugging a square star pattern printing program helps beginners understand common programming errors and how to fix them. It teaches them to read and understand error messages, identify the source of the error, and make necessary corrections.

• Building Confidence : Successfully writing and executing a square star pattern printing program can boost a beginner's confidence. It demonstrates their ability to apply programming concepts in a practical setting and motivates them to tackle more complex programming challenges.

• Learning Fundamental Programming Concepts : The square star pattern printing program teaches beginners fundamental programming concepts such as loops, conditional statements, and variable manipulation. These concepts form the foundation of programming and are essential for beginners to grasp.

• Encourages Creativity : While the square star pattern may seem simple, there are various ways to customize it and create unique designs. This encourages creativity as beginners experiment with different patterns and shapes using the same basic concept.

## Tips for Writing Square Star Pattern Printing Programs in C

• Use Nested Loops : To print a square star pattern, use nested loops—one for rows and one for columns. The outer loop controls the number of rows, while the inner loop controls the number of stars in each row.

• Use Variables for Size : Use variables to store the size of the square (i.e., the number of rows and columns) to make the program more flexible. This allows you to easily change the size of the square without modifying the code.