Find the Perimeter and area of a Rectangle

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.

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

Comments

Most Viewed

Write C program to enter any year and check whether year is leap year or not using conditional/ternary operator.

WAP to input week number and print week day name.

C Program to Find Third Angle of a Triangle