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



#include<stdio.h>
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
            else 
                printf(" "); 
			/* leaves the middle columns of rectangle blank*/
        }
        printf("\n"); 
    }
    return 0;
}

Output

Output - Hollow rectangle






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.