ADVERTISEMENT
ADVERTISEMENT

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

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

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

Area and perimeter of a rectangle in C

/* 	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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.