Signup/Sign In

C Program to Print Hollow Square Pattern Program

Learn C language

Logic To Print Hollow Square Pattern Program:

  • Get the input from the user to print the number of rows
  • Store the value in variable
  • Print the Number of stars in the first and last row
  • Print only two stars in the first column and last column of other rows

Algorithm To Print Hollow Square Pattern Problem:

  • Store the values in the variable,
  • By using the outer loop from 1 to x, the structure of the outer loop is i=1; i<=x;i++
  • By using the inner loop from 1 to x, define the inner loop as j=1; j<=x; j++
  • Within the inner loop print the symbol in the first and last column,
  • Print the symbol in the first and last column of every row.

C language Program To Print The Hollow Square Pattern Program:

#include <stdio.h>

int main()
{
    int i, j, N;

    /* Code Block To Get The Input From The User */
    printf("Enter number of rows To Print Hollow Square : ");
    scanf("%d", &N);

   
    for(i=1; i<=N; i++)
    {
       
        for(j=1; j<=N; j++)
        {
            if(i==1 || i==N || j==1 || j==N)
            {
                /* Code Bloack To Print The First & Last Column */
                printf("*");
            }
            else
            {
                printf(" ");
            }
        }

        
        printf("\n");
    }

    return 0;
}

Output:

hollow Square



About the author:
I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight