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

C Program To Calculate Perimeter, Diagonal of a Square using its Side

Lets write a C program to calculate area, perimeter and diagonal of a square by using length of its side. We ask the user to input the length of its side.

Related Read:
C Program To Calculate Area of a Square using its Side
C Program To Calculate Area of a Square using its Diagonal

Formula To Calculate Area, Perimeter and Diagonal of a Square using its side

diagonal = sqrt(2) x side;

area = ( diagonal x diagonal ) / 2.0
OR
area = ( diagonal x diagonal ) * 0.5
OR
area = side x side;

Perimeter = 4 x side;

Note: All the sides of a square are equal. Both the diagonals of the square are of equal length.

diagonal of square using its side

Expected Output for the Input

User Input:
Enter length of side of the Square
10.5

Output:
Area of the Square is 110.250000
Perimeter of the Square is 42.000000
Diagonal of the Square is 14.849242

Video Tutorial: C Program To Calculate Perimeter, Diagonal of a Square using its Side


[youtube https://www.youtube.com/watch?v=QXO-lF-EbvA]

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

Source Code: C Program To Calculate Perimeter, Diagonal of a Square using its Side

#include < stdio.h >
#include < math.h >

int main()
{
    float perimeter, diagonal, side, area;

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

    perimeter = 4 * side;
    diagonal  = sqrt(2) * side;
    area      = side * side;

    printf("Area of the Square is %f\n", area);
    printf("Perimeter of the Square is %f\n", perimeter);
    printf("Diagonal of the Square is %f\n", diagonal);

    return 0;
}

Output 1:
Enter length of side of the Square
10
Area of the Square is 100.000000
Perimeter of the Square is 40.000000
Diagonal of the Square is 14.142136

Output 2:
Enter length of side of the Square
5
Area of the Square is 25.000000
Perimeter of the Square is 20.000000
Diagonal of the Square is 7.071068

Output 3:
Enter length of side of the Square
12.2
Area of the Square is 148.839996
Perimeter of the Square is 48.799999
Diagonal of the Square is 17.253405

Output 4:
Enter length of side of the Square
10.5
Area of the Square is 110.250000
Perimeter of the Square is 42.000000
Diagonal of the Square is 14.849242

Output 5:
Enter length of side of the Square
3.2
Area of the Square is 10.240001
Perimeter of the Square is 12.800000
Diagonal of the Square is 4.525484

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

C Program To Calculate Area of a Square using its Diagonal

Lets write a C program to find area of a square by using length of its diagonal. We ask the user to input the length of its diagonal.

Related Read:
C Program To Calculate Area of a Square using its Side

Formula To Calculate Area of Square using its diagonal

area = ( diagonal x diagonal ) / 2.0
OR
area = ( diagonal x diagonal ) * 0.5

Note: All the sides of a square are equal. Both the diagonals of the square are of equal length.

area of square using its diagonal

Expected Output for the Input

User Input:
Enter length of diagonal of a Square
15.2

Output:
Area of the Square is 115.52

Video Tutorial: C Program To Calculate Area of a Square using its Diagonal


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

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

Source Code: C Program To Calculate Area of a Square using its Diagonal

#include < stdio.h >

int main()
{
    float area, diagonal;

    printf("Enter length of diagonal of a Square\n");
    scanf("%f", &diagonal);

    area = (diagonal * diagonal) * 0.5;

    printf("Area of the Square is %0.2f\n", area);

    return 0;
}

Output 1:
Enter length of diagonal of a Square
9
Area of the Square is 40.50

Output 2:
Enter length of diagonal of a Square
5
Area of the Square is 12.50

Output 3:
Enter length of diagonal of a Square
10
Area of the Square is 50.00

Output 4:
Enter length of diagonal of a Square
10.5
Area of the Square is 55.13

Output 5:
Enter length of diagonal of a Square
12.2
Area of the Square is 74.42

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

C Program To Calculate Area of a Square using its Side

Lets write a C program to find area of a square by using length of its side. We ask the user to input the length of its side.

Formula To Calculate Area of Square using its side

area = side x side.

Note: All the sides of a square are equal.

Expected Output for the Input

User Input:
Enter the length of side of a square
5

Output:
Area of the Square is 25.00

Video Tutorial: C Program To Calculate Area of a Square using its Side


[youtube https://www.youtube.com/watch?v=V-nCBIaMmYQ]

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

Source Code: C Program To Calculate Area of a Square using its Side

#include < stdio.h >

int main()
{
    float area, side;

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

    area = side * side;

    printf("Area of the Square is %0.2f \n", area);

    return 0;
}

Output 1:
Enter the length of side of a square
3
Area of the Square is 9.00

Output 2:
Enter the length of side of a square
4
Area of the Square is 16.00

Output 3:
Enter the length of side of a square
5
Area of the Square is 25.00

Output 4:
Enter the length of side of a square
6
Area of the Square is 36.00

Output 5:
Enter the length of side of a square
8
Area of the Square is 64.00

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

Perimeter of Rectangle: C Program

The length and breadth / width of a rectangle are entered through the keyboard. Write a program to calculate the perimeter of the rectangle.

To get perimeter of a rectangle, we add the length and width of rectangle and then multiply it with 2. In other words, perimeter is the addition of length of all the sides of a rectangle.

Related Read:
Basic Arithmetic Operations In C
Area of Rectangle: C Program

Note: Perimeter of a Rectangle is calculated using the formula
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.

Find Perimeter of a Rectangle: C Program


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

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


Source Code: Find Perimeter of a Rectangle: C Program

#include < stdio.h >

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

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

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

    perimeter = 2 * (length + width);

    printf("Perimeter of Rectangle is %f\n", perimeter);

    return 0;
}

Output:
Enter length of Rectangle
12
Enter width of Rectangle
6
Perimeter of Rectangle is 36.000000

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