C Program To Find Whether Area of Rectangle Is Greater Than Its Perimeter


Given the length and breadth(or width) of a rectangle, write a C program to find whether the area of the rectangle is greater than its perimeter. For example, the area of the rectangle with length = 5 and breadth = 4 is greater than its perimeter.

Related Read:
Area of Rectangle: C Program
Perimeter of Rectangle: C Program

Note:
Rectangle is a quadrilateral(i.e., it has 4 sides). And all the 4 angles of the rectangle are of 90 degree. To calculate area of a rectangle we need its length and width/breadth.

Formula To Calculate Area of a Rectangle

Area = Length * Width;
area of rectangle

Formula To Calculate Perimeter of a Rectangle

Perimeter = 2 * (Length + Width);
perimeter of rectangle

Length: is the length of the longest side of the rectangle.
width: is the length of the smallest side of the rectangle.

Expected Output for the Input

User Input:
Enter length of the Rectangle
5
Enter width of the Rectangle
4

Output:
yes, area(20.00) is greater than its perimeter(18.00)

Video Tutorial: C Program To Find Whether Area of Rectangle Is Greater Than Its Perimeter


[youtube https://www.youtube.com/watch?v=TmnErbGucfk]

YouTube Link: https://www.youtube.com/watch?v=TmnErbGucfk [Watch the Video In Full Screen.]

Source Code: C Program To Find Whether Area of Rectangle Is Greater Than Its Perimeter

#include < stdio.h >

int main()
{
    float length, width, area, perimeter;

    printf("Enter length of the Rectangle\n");
    scanf("%f", &length);

    printf("Enter width of the Rectangle\n");
    scanf("%f", &width);

    area      =     (length * width);
    perimeter = 2 * (length + width);

    if(area > perimeter)
    {
        printf("yes, area(%0.2f) is greater than its perimeter(%0.2f)\n", 
               area, perimeter);
    }
    else
    {
        printf("Area(%0.2f) is not greater than its perimeter(%0.2f)\n", 
               area, perimeter);
    }

    return 0;
}

Output:
Enter length of the Rectangle
12
Enter width of the Rectangle
6
yes, area(72.00) is greater than its perimeter(36.00)

Logic To Find Whether Area of Rectangle Is Greater Than Its Perimeter

We ask the user to enter length and breadth/width of the rectangle and store it inside address of variable length and width. Next we calculate area and perimeter of the rectangle using the user entered value for length and width of the rectangle.

Area = Length * Width;
Perimeter = 2 * (Length + Width);

Next we check if the value present in variable area is greater than the value of perimeter or not, and output the result accordingly to the console window.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

Your email address will not be published. Required fields are marked *