🚀Beginner

Area and Perimeter of Rectangle

Calculate area and perimeter

A rectangle is a quadrilateral with four right angles. This program calculates both the area (space inside) and perimeter (boundary length) of a rectangle given its length and width.

📐 Formulas

Area

A = L × W

(square units)

Perimeter

P = 2(L + W)

(linear units)

📏 Rectangle Diagram

Length (L)Width (W)Area = L × W

C Program to Find Area and Perimeter of Rectangle

area_rectangle.c
C
1#include <stdio.h>
2
3int main() {
4 float length, width, area, perimeter;
5
6 // Input dimensions
7 printf("Enter length of rectangle: ");
8 scanf("%f", &length);
9
10 printf("Enter width of rectangle: ");
11 scanf("%f", &width);
12
13 // Calculate area and perimeter
14 area = length * width;
15 perimeter = 2 * (length + width);
16
17 // Display results
18 printf("\nArea of rectangle = %.2f sq. units\n", area);
19 printf("Perimeter of rectangle = %.2f units\n", perimeter);
20
21 return 0;
22}
Output

Enter length of rectangle: 10

Enter width of rectangle: 5

 

Area of rectangle = 50.00 sq. units

Perimeter of rectangle = 30.00 units

📝 Step-by-Step Calculation

Given: Length = 10, Width = 5

Area = 10 × 5 = 50 sq. units

Perimeter = 2 × (10 + 5) = 2 × 15 = 30 units

🎯 Key Takeaways

Area = Length × Width
Perimeter = 2 × (L + W)
Area is in square units
Perimeter is in linear units

Want to Learn More?

Explore our comprehensive tutorials for in-depth explanations of C programming concepts.

Browse Tutorials
Back to All Examples