C Program to Enter Length and Breadth of a Rectangle and Find its Perimeter
C program to enter length and breadth of a rectangle and find its perimeter.
In this article, you will learn how to write a c program to enter length and breadth of a rectangle and find its perimeter.
You should have knowledge of the following topics in c programming.
- C
main()
function - C
printf()
function
Formula
This is the standard formula to calculate the perimeter of a rectangle.
P = 2(l + w)
Where
P = perimeter
l = length of the rectangle
w = width of the rectangle
Source Code
// C Program to Enter Length and Breadth of a Rectangle and Find its Perimeter
#include <stdio.h>
int main() {
float l, w, p;
printf("Enter the length & width of the rectangle::\n");
scanf("%f", &l);
scanf("%f", &w);
// Calculate perimeter of rectangle
p = 2 * (l + w);
// It will print the final output
printf("\nThe Perimeter of rectangle = %f units ", p);
return 0;
}
Output
Enter the length & width of the rectangle::
5
7
The perimeter of rectangle = 24.000000 units
Explanation
In this program, we have taken two inputs from the user rectangle's width 5
and rectangle's height 7.
Then used the standard formula P = 2(l + w)
to calculate the perimeter of a rectangle then it will return the 24.000000 units
the perimeter of the rectangle.