In this tutorial you will learn about the C Program to Find Perimeter of a Rectangle using Length and Width and its application with practical example.
C Program to Find Perimeter of a Rectangle using Length and Width
In this tutorial, we will learn to create a C program that will Find the Perimeter of a Rectangle using Length and Width 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.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input length and the width of the <strong>Rectangle </strong>from the user. 3. <strong>C</strong><strong>alculating the Perimeter of a Rectangle </strong>using the arithmetic expression length * width. 4. Printing the Perimeter of the <strong>Rectangle</strong>. 5. End the program. |
Program description:-
In this tutorial, we will create a program, that will find the Perimeter of the Rectangle. we will First, take the length and the width of the Rectangle from the user. Then we will calculate the Perimeter of the Rectangle using arithmetic expressions / the formulae for the Perimeter of the Rectangle. At last, we will print the Perimeter of the Rectangle.
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 |
/* C Program to find Perimeter of a Rectangle using length and width */ #include<stdio.h>//including the header files for the program int main()//body of the main function. { //declaring the required variablefor the program float wd, lt, pmr; //wd = it will hold float value of the input from the user for width. //lt = it will hold the perimeter of the for the Rectangle. //Taking the input width from the user. printf ("\n Please Enter the Width of a Rectangle : "); //Scanning the input from the user. scanf ("%f",&wd); //Taking the input height from the user. printf ("\n Please Enter the Length of a Rectangle : "); //Scanning the input from the user. scanf ("%f",<); //Calculating the perimeter of the Rectangle. pmr = 2 * (lt + wd); //Printing The Perimeter of the Rectangle. printf("\n Perimeter of a Rectangle = %.2f", pmr); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- wd = it will hold the input value for the base of the Rectangle.
- lt = it will hold the input value for the height of the Rectangle.
- pmr = it will hold the value of the area of the Rectangle.
Taking the input width and the length of the Rectangle.
Calculating the Perimeter of the Rectangle.
Printing the Perimeter of the Rectangle.