C Program To Calculate Area of Rhombus

Lets write a C program to calculate area of a Rhombus using its side and a diagonal. We ask the user to input the value of side and a diagonal.

A Rhombus is a polygon having 4 equal sides in which both the opposite sides are parallel and opposite angles are equal.

area of rhombus

First we calculate the value of second diagonal. Once we know the value of both the diagonals of the Rhombus, its easy and straightforward to calculate the area of Rhombus using the formula:

q = sqrt( (4 x side x side) – (p x p) );
p = sqrt( (4 x side x side) – (q x q) );

area = (p x q) / 2.0;
OR
area = (p x q) x 0.5;

where p and q are diagonals of the Rhombus.

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 Area of Rhombus


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

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

Source Code: C Program To Calculate Area of Rhombus

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

int main()
{
    float area, side, p, q;

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

    q    = sqrt( (4 * side * side) - (p * p) );
    area = (p * q) * 0.5;

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

    return 0;
}

Output 1:
Enter the length of side and a diagonal
5
7.07
Area of the Rhombus is 25.000000

Output 2:
Enter the length of side and a diagonal
10
16
Area of the Rhombus is 96.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

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