In this article we will show you, 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.

## Area of a Rectangle

If we know the width and height then, we can calculate the area of a rectangle using below formula.

Area = Width * Height

Perimeter is the distance around the edges. We can calculate perimeter of a rectangle using below formula

Perimeter = 2 * (Width + Height)

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

This program allows the user to enter width and height of the rectangle. Using those values we will calculate the Area of a rectangle and perimeter of a rectangle.

**CODE**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/* 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**

Following statements will allow the User to enter the Width and Height of a rectangle.

1 2 |
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

1 |
Area = width * height |

In the next line, We are calculating the Perimeter of the rectangle

1 |
Perimeter = 2 *(width + height) |

Following printf statements will help us to print the Perimeter and Area of a rectangle

1 2 |
printf("\n Area of a rectangle is: %.2f", Area); printf("\n Perimeter of a rectangle is: %.2f", Perimeter); |

Thank You for Visiting Our Blog

## Leave a Reply