Required knowledge
Basic C programming,?For loop,?Nested loop
Logic to print square star pattern
?
*****
*****
*****
*****
*****
?
Have a close look to the pattern for a minute so that you can think a little basic things about the pattern.
The pattern is a matrix of?N?rows and columns containing stars(asterisks). Here, you need to iterate through?N?rows, and for each row iterate for?N?columns.
Step by step descriptive logic to print the square number pattern.
- Input number of rows from user. Store it in some variable say?N.
- To iterate through rows, run an outer loop from 1 to?N. The loop structure should be similar to?
for(i=1; i<=N; i++).
- To iterate through columns, run an inner loop from 1 to?N. Define a loop inside above loop with structure?
for(j=1; j<=N; j++).
- Inside inner loop print?*.
- After printing all columns of a row move to next line i.e. print a new line.