Q:

C program to find area and perimeter of the rectangle

0

C program to find area and perimeter of the rectangle

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

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C programming Basic Input, Output, if else, Ternary Operator based Programs

Similar questions


need a help?


find thousands of online teachers now
C program to generate random numbers within a rang... >>
<< Calculate the distance between two cities from kil...