How to write C Program to Calculate Area Of a Rectangle and Perimeter of a Rectangle with example?. Before we step into the program, Let see the definitions and formulas behind Perimeter and Area Of a Rectangle in C.

## Area 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 formula

Perimeter = 2 * (Width + Height)

## C Program to Calculate Area of a Rectangle and Perimeter of a Rectangle

This C 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 perimeter of a rectangle.

/* C Program to Calculate Area of a Rectangle and 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; }

**OUTPUT**

**ANALYSIS**

The following statements 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 are calculating the area as per the formula

Area = width * height

In the next line of the C Program to Calculate Area of a Rectangle example, we are calculating the Perimeter of the rectangle

Perimeter = 2 *(width + height)

The following 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);