Home / Programs / C program to find perimeter of a rectangle
Programming Example

C program to find perimeter of a rectangle

👁 3,675 Views
💻 Practical Program
📘 Step by Step Learning

The perimeter of a rectangle is the total length of all the sides of the rectangle. Hence, we can find the perimeter by adding all four sides of a rectangle. Perimeter of the given rectangle is l + w + l + w = 2 * (l + w).

Flow chart

C program to find perimeter of a rectangle

Program Code

/**
 * C program to find perimeter of 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("Perimeter of rectangle = %f units \n", perimeter);
 
    return 0;
} 

Output

Enter length of the rectangle: 6
Enter width of the rectangle: 5
Perimeter of rectangle = 22.000000 units
Press any key to continue . . .

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.