Write a C program to input length and width of a rectangle from user and calculate perimeter of the rectangle. How to find perimeter of a rectangle if length and breadth of a rectangle are given using C programming.

Input length: 5

Input Width: 10

Perimeter of rectangle = 30 units

Where

Happy coding ;)

**Example:**Input length: 5

Input Width: 10

Perimeter of rectangle = 30 units

### Required knowledge:

Fundamentals of C, Data types, Taking user input in C, Perimeter of rectangle#### Perimeter of rectangle:

Perimeter of a rectangle can be expressed using below formula:Where

*l*is the length and*w*is the width of rectangle.### Program:

/** * C program to find perimeter of a rectangle */ #include <stdio.h> int main() { float length, width, perimeter; /* * Reads length and width of rectangle from user */ printf("Enter length of the rectangle: "); scanf("%f", &length); printf("Enter width of the rectangle: "); scanf("%f", &width); /* Calculates perimeter of rectangle */ perimeter = 2 * (length + width); /* Prints perimeter of rectangle */ printf("\nPerimeter of rectangle = %f units ", perimeter); return 0; }

Output

Enter length of the rectangle: 5

Enter width of the rectangle: 10

Perimeter of rectangle = 30.000000

Enter width of the rectangle: 10

Perimeter of rectangle = 30.000000

Happy coding ;)

### You may also like

- Basic programming exercises in C.
- C program to find sum of two numbers.
- C program to enter two numbers and perform all arithmetic operations.
- C program to find area of rectangle.
- C program to find diameter, circumference and area of circle.
- C program to find third angle of triangle if two angles are given.
- C program to check whether a triangle is valid or not if all angles are given.
- C program to calculate area of equilateral triangle.
- C program to check whether a triangle is Equilateral, Isosceles or Scalene triangle.
- C program to calculate total, average and percentage.
- C program to find maximum between two numbers.

< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).