In this tutorial you will learn about the C Program To Print Hollow Rectangle Star Pattern and its application with practical example.
C Program To Print Hollow Rectangle Star Pattern
In this tutorial, we will learn to create a C program that will Print Hollow Rectangle Star Pattern in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Arithmetic operations in C programming.
What is a rectangle?
The rectangle is four sides geometrical shape with pair of two sides parallel and of the same size as each other. The Rectangle has the length and the width in it.
The perimeter is the total of all the borders of the shape rectangle. In the hollow rectangle, we will only print the perimeter of the rectangle.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input rows and the columns of the <strong>Rectangle </strong>from the user. 3. Generating <strong>the pattern of hollow Rectangle </strong>using the. 4. Printing the pattern <strong> hollow Rectangle</strong>. 5. End the program. |
Program description:-
In this tutorial, we will create a program, that will print the hollow Rectangle pattern. we will First, take the rows and the columns of the Rectangle from the user. Then we will print the hollow rectangle pattern using the for loops. At last, we will print the pattern of hollow Rectangle pattern.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
/* C Program to Print Hollow Rectangle Star Pattern */ #include<stdio.h> int main() { //declaring the required variables for the program. int i, j, rw, clm; //i,j = it will hold the integer value for the controlling of the loops //Taking the input number of rows from the user. printf("Please Enter the Number of rows: \n"); //Scanning the rows scanf("%d", &rw); //Taking the input number of columns from the user. printf("Please Enter the Number of column: \n"); //Scanning the columns scanf("%d", &clm); //Generating the pattern using the for loops for(i = 0; i < rw; i++) { for(j = 0; j < clm; j++) { if(i == 0 || i == rw-1 || j == 0 || j == clm-1) { //printing the pattern using borders of the rectangle. printf("*"); } else { //printing the hollow spaces in the pattern. printf(" "); } } printf("\n"); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- rw = it will hold the input value for the rows of the Rectangle.
- clm = it will hold the input value for the columns of the Rectangle.
- i, j = it will hold the value for controlling the loop.
Taking the input rows and the columns of the Rectangle.
Generating the pattern using the for loop to print the Rectangle.
Printing the pattern of the Rectangle.