C Program to Find the Perimeter and Area of a Rectangle

  • Write a C program to find perimeter and area of rectangle.
  • WAP in C to find perimeter of a rectangle.

Required Knowledge


To find the perimeter and area of rectangle, we will first take length and breadth of rectangle as input from user using scanf function and then calculate area and perimeter of rectangle using following formulae.

  • Perimeter of Rectangle = 2 x (length + width)
  • Area of Rectangle = length x width

C program to find the perimeter and area of rectangle

/* 
 *  C program to find perimeter and area of Rectangle, 
 *  Given its length and Breadth
 */  
  
#include <stdio.h>  

int main() {  
    float length, width, area, perimeter; 
  
    /* 
     * Take length and breadth as input from user using scanf 
     */  
    printf("Enter length of Rectangle\n");  
    scanf("%f", &length);  
    printf("Enter width of Rectangle\n");  
    scanf("%f", &width);  
  
    /* Perimeter of Rectangle = 2 x (length + width) */  
    perimeter = 2 * (length + width);  
    printf("Perimeter of Rectangle : %f\n", perimeter); 
    
    /* Area of Rectangle = length x width */  
    area = length * width;
    printf("Area of Rectangle : %f\n", area);
  
    return 0;  
}  

Output
Enter length of Rectangle
3.5
Enter width of Rectangle
5
Perimeter of Rectangle : 17.000000
Area of Rectangle : 17.500000

Related Topics
C program to calculate area of a rectangle
C program to calculate area of a parallelogram
C program to calculate area of a rhombus
C program to calculate area of a trapezium
C program to calculate area of a square
C program to calculate area of any triangle
C program to calculate volume and total surface area of cylinder
C program to calculate volume and total surface area of sphere
C program to calculate area of an equilateral triangle
List of all C programs