C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

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

Liked this article? Do share with your friends :)

Are you a blogger? Join our Blogging forum.