C Program to Calculate Area, Perimeter and Side of a Rhombus

Rhombus Properties Calculator
Area, Perimeter and Side of a Rhombus

Introduction

In geometry, a rhombus is a type of quadrilateral where all four sides are equal in length. The main properties of a rhombus are its area, perimeter, and side length. Given the diagonals of a rhombus, we can calculate these properties using the following formulas:

  • Area = (diagonal1 * diagonal2) / 2
  • Perimeter = 4 * side
  • Side = sqrt((diagonal1 / 2)² + (diagonal2 / 2)²)


Code


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

// Function to calculate area, perimeter, and side of the rhombus
void calculateRhombusProperties(double diagonal1, double diagonal2) {
    double area, perimeter, side;
    
    // Calculate area
    area = (diagonal1 * diagonal2) / 2;
    
    // Calculate side using Pythagorean theorem
    side = sqrt(pow(diagonal1 / 2, 2) + pow(diagonal2 / 2, 2));
    
    // Calculate perimeter
    perimeter = 4 * side;
    
    // Display results
    printf("Area of Rhombus: %.2f\n", area);
    printf("Perimeter of Rhombus: %.2f\n", perimeter);
    printf("Side of Rhombus: %.2f\n", side);
}

int main() {
    double diagonal1, diagonal2;
    
    // Input diagonals from the user
    printf("Enter the length of the first diagonal: ");
    scanf("%lf", &diagonal1);
    printf("Enter the length of the second diagonal: ");
    scanf("%lf", &diagonal2);
    
    // Function call to calculate properties
    calculateRhombusProperties(diagonal1, diagonal2);
    
    return 0;
}
    


Output

Example:


Enter the length of the first diagonal: 10
Enter the length of the second diagonal: 8
Area of Rhombus: 40.00
Perimeter of Rhombus: 26.08
Side of Rhombus: 6.52
    


Explanation

  • Input: The user enters the lengths of the two diagonals of the rhombus.
  • Area Calculation: The area is calculated by the formula (diagonal1 * diagonal2) / 2.
  • Side Calculation: The side of the rhombus is derived using the Pythagorean theorem: side = sqrt((diagonal1 / 2)² + (diagonal2 / 2)²).
  • Perimeter Calculation: The perimeter is then computed as 4 * side.
  • Output: Finally, the program displays the area, perimeter, and side length, each formatted to two decimal places.