a program in c with detail explanation to print the pattern of a hollow square using a while loop.

1. Enter the number of lines to be printed from the user. Store it in a variable, for example N.
2. Run an outer loop from 1 to N to iterate through the rows. Define the for(i=1; i<=N; i++) structure for this loop.
3. Run an inner loop from 1 to N to iterate over the columns. Define a loop with the structure for(j=1; j<=N; j++).
4. Inside the inner loop, type an asterisk for the first and last row or the first and last column. Which, if i==1, i==N, j==1, or j==N, will output
an asterisk, otherwise a space.
5. After printing all the columns of a row, go to the next row, i.e. print an empty row after the inner loop.


Program to print hollow square pattern

						

/** * Program in c to show hollow square star pattern */ #include <stdio.h> int main() { int i, j, N; /* accept number of rows as input from user */ printf("\nEnter number of rows:\n "); scanf("%d", &N); /* Iterate through each row */ for(i=1; i<=N; i++) { /* Iterate through each column */ for(j=1; j<=N; j++) { if(i==1 || i==N || j==1 || j==N) { /* print the star for 1st Nth column and row */ printf("*"); } else { printf(" "); } } /* Move to the next line/row */ printf("\n"); } return 0; }


Previous :-->> 15.Write a program in c language to find the sum of all digits of a given number.
 -->> NEXT: 17. Write a program in c to check if a given number is a perfect number or not using a do while loop.
-->>ALL Loops Assignments in c