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

Leave a Reply

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