How to Write C Program to Calculate the Area Of a Rectangle and the Perimeter of a Rectangle with an example? Before we step into the program, let’s see the definitions and formulas to calculate the Area and Perimeter Of a Rectangle.
If we know the width and height, we can calculate the area of a rectangle using the below formula.
Area = Width * Height
Perimeter is the distance around the edges. We can calculate the perimeter of a rectangle using the below shown mathematical formula.
Perimeter = 2 * (Width + Height)
C Program to Calculate Area and Perimeter of a Rectangle
This Program allows the user to enter the width and height of the rectangle. Using those values, we will calculate the Area of a rectangle and the perimeter of a rectangle.
#include<stdio.h>
int main()
{
float width, height, Area, Perimeter;
printf ("\n Please Enter the Width and Height of the rectangle \n");
scanf (" %f %f ",&width, &height);
Area = width * height;
Perimeter = 2 *(width + height);
printf("\n Area of a rectangle is: %.2f", Area);
printf("\n Perimeter of a rectangle is: %.2f", Perimeter);
return 0;
}

The following statements in this C program will allow the User to enter the Width and Height of a rectangle.
printf ("\n Please Enter the Width and Height of the rectangle \n");
scanf (" %f %f ",&width, &height);
Next, we calculate the area as per the below math formula.
Area = width * height
In the next line of the Program to Area of a Rectangle example, we are calculating the Perimeter of the same.
Perimeter = 2 *(width + height)
The following C Programming printf statements will help us to print the Perimeter and Area of a rectangle.
printf("\n Area of a rectangle is: %.2f", Area);
printf("\n Perimeter of a rectangle is: %.2f", Perimeter);
C Program to find Area of a Rectangle using length and width
This program allows the user to enter the length and width of a rectangle. Using those values, this Programming language will calculate the area of a rectangle.
TIP: If we know the length and width of a rectangle, then we can calculate the area of a rectangle using formula : Area = Length * Width.
#include<stdio.h>
int main()
{
float width, length, Area;
printf ("\n Please Enter the Width of a Rectangle : ");
scanf ("%f",&width);
printf ("\n Please Enter the Length of a Rectangle : ");
scanf ("%f",&length);
Area = length * width;
printf("\n The Area of a Rectangle = %.2f", Area);
return 0;
}

Also Read
- C Program to find Perimeter of a Rectangle using Length and Width
- C Program to find the Area of a Parallelogram