C program to find perimeter of a rectangle

Category: C Program

Write a C program to enter the length and breadth of a rectangle and find its perimeter using operators and the formula.

To find perimeter of a rectangle we have to use the formula -

PERIMETER = 2 * (LENGTH + BREADTH)

And we can use operators to implement the same formula in our C program.

Example -

Input: Enter length of the rectangle: 10
       Enter breadth of the rectangle: 20
Output: Perimeter of rectangle: 60.000000

C program to find perimeter of a rectangle

#include <stdio.h>

void main()
{
    float length, breadth, perimeter;

    printf("Enter length of the rectangle: ");
    scanf("%f", &length);
    printf("Enter breadth of the rectangle: ");
    scanf("%f", &breadth);

    perimeter = 2 * (length + breadth);

    printf("Perimeter of rectangle: %f", perimeter);
}

Output

Enter length of the rectangle: 10
Enter breadth of the rectangle: 20
Perimeter of rectangle: 60.000000

Recommended Posts