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 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;
} 
                        

🖥 Program Output

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

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.