Home » C programs

C program for 'Hollow Rectangle' Pattern

In this c program, we are going to read total number of rows, columns and print a 'Hollow Rectangle'.
Submitted by Shamikh Faraz, on February 14, 2018

In this program we will learn, how we can print hollow rectangle using ‘asterisks’ and ‘loops’.

C program

int main(){
    int columns, rows, a, b;
    printf("Enter number of rows\t");
    scanf("%d", &rows);
    printf("Enter number of columns\t");
    scanf("%d", &columns);
    /*this loop increase number of rows */
	for(a = 0; a < rows; a++)  
		/*this loop increase number of columns */
        for(b = 0; b < columns; b++) 
            /* this puts the star on boudaries */
			if(a==0 || a==rows-1 || b==0 || b==columns-1)             
                printf("*"); //prints the star
                printf(" "); 
			/* leaves the middle columns of rectangle blank*/
    return 0;


Output - Hollow rectangle

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.

Comments and Discussions

© https://www.includehelp.com (2015-2018), Some rights reserved.

close Like other websites, this site uses cookies to deliver relevant ads based on your interest, by using our website, you acknowledge that you have read our privacy policy.