C program to find area and perimeter of the rectangle

Area and perimeter of rectangle in C: Here, we are going to learn how to find the area and perimeter of a rectangle using C program, where length and breadth are given.
Submitted by Manju Tomar, on August 01, 2019

Problem statement

Input length and breadth and calculate the area and perimeter of a rectangle using C program.

Formulas to find area and perimeter of the rectangle

Formula to calculate area of a rectangle: length * breadth

Formula to calculate perimeter of a rectangle: 2*length + 2*breadth or 2(length + breadth)

Example

Input:
length: 2.55
breadth: 10

Output:
Area: 25.50 
Perimeter: 25.10

C program to find area and perimeter of the rectangle

/* 	C program to calculate the area and perimeter 
	of rectangle 
*/

#include <stdio.h>

int main()
{
    /*declare the variables*/
    float length;
    float breadth;
    float area;
    float perimeter;

    /*length input*/
    printf("Enter the length: ");
    scanf("%f", &length);

    /*breadth input*/
    printf("Enter the breadth: ");
    scanf("%f", &breadth);

    /*Calculating the area and rectangle*/
    area = length * breadth;
    perimeter = (2 * length) + (2 * breadth);

    /*printing the result*/
    printf("Area of the rectangle: %.02f\n", area);
    printf("Perimeter of rectangle: %.02f\n", perimeter);

    return 0;
}

Output

First run:
Enter the length: 5
Enter the breadth: 4 
Area of the rectangle: 20.00 
Perimeter of rectangle: 18.00

Second run:
Enter the length: 2.55 
Enter the breadth: 10
Area of the rectangle: 25.50 
Perimeter of rectangle: 25.10

C Basic Programs »


Related Programs

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.