Program to find area and peremeter of rhombus
- Write a program to find area and peremeter of rhombus in C
- Write a program to find area and peremeter of rhombus in C++
- Write a program to find area and peremeter of rhombus in Python
- Write a program to find area and peremeter of rhombus in PHP
- Write a program to find area and peremeter of rhombus in Java
- Write a program to find area and peremeter of rhombus in Java Script
- Write a program to find area and peremeter of rhombus in C#
Explanation:
A rhombus is a kind of quadrilateral in which the opposite angles and lengths of all four sides are equal. A rhombus’s diagonals bisect one another and intersect at right angles.
Formulas:
Area (A): The area of a rhombus can be calculated in two ways:
- Using the diagonals: Area=0.5 × Diagonal1 × Diagonal2
- Using base and height: Area = Base × Height
Perimeter (P): Since all sides of a rhombus are equal: Perimeter = 4 × Side
Program to find area and peremeter of rhombus
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h>
int main() {
float d1, d2, side, area, perimeter;
// Input the diagonals and side length
printf("Enter the length of the first diagonal (d1): ");
scanf("%f", &d1);
printf("Enter the length of the second diagonal (d2): ");
scanf("%f", &d2);
printf("Enter the side of the rhombus: ");
scanf("%f", &side);
// Calculating area and perimeter
area = (d1 * d2) / 2;
perimeter = 4 * side;
printf("Area of the rhombus: %.2f\n", area);
printf("Perimeter of the rhombus: %.2f\n", perimeter);
return 0;
}
#include <iostream>
using namespace std;
int main() {
double d1, d2, side, area, perimeter;
cout << "Enter the length of the first diagonal (d1): ";
cin >> d1;
cout << "Enter the length of the second diagonal (d2): ";
cin >> d2;
cout << "Enter the side of the rhombus: ";
cin >> side;
area = (d1 * d2) / 2;
perimeter = 4 * side;
cout << "Area of the rhombus: " << area << endl;
cout << "Perimeter of the rhombus: " << perimeter << endl;
return 0;
}
d1 = float(input("Enter the length of the first diagonal (d1): "))
d2 = float(input("Enter the length of the second diagonal (d2): "))
side = float(input("Enter the side of the rhombus: "))
area = (d1 * d2) / 2
perimeter = 4 * side
print(f"Area of the rhombus: {area:.2f}")
print(f"Perimeter of the rhombus: {perimeter:.2f}")
<?php echo "Enter the length of the first diagonal (d1): "; $d1 = (float)readline(); echo "Enter the length of the second diagonal (d2): "; $d2 = (float)readline(); echo "Enter the side of the rhombus: "; $side = (float)readline(); $area = ($d1 * $d2) / 2; $perimeter = 4 * $side; echo "Area of the rhombus: " . number_format($area, 2) . "\n"; echo "Perimeter of the rhombus: " . number_format($perimeter, 2) . "\n"; ?>
import java.util.Scanner;
public class RhombusProperties {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the length of the first diagonal (d1): ");
double d1 = scanner.nextDouble();
System.out.print("Enter the length of the second diagonal (d2): ");
double d2 = scanner.nextDouble();
System.out.print("Enter the side of the rhombus: ");
double side = scanner.nextDouble();
double area = (d1 * d2) / 2;
double perimeter = 4 * side;
System.out.printf("Area of the rhombus: %.2f\n", area);
System.out.printf("Perimeter of the rhombus: %.2f\n", perimeter);
scanner.close();
}
}
const d1 = parseFloat(prompt("Enter the length of the first diagonal (d1):"));
const d2 = parseFloat(prompt("Enter the length of the second diagonal (d2):"));
const side = parseFloat(prompt("Enter the side of the rhombus:"));
const area = (d1 * d2) / 2;
const perimeter = 4 * side;
console.log(`Area of the rhombus: ${area.toFixed(2)}`);
console.log(`Perimeter of the rhombus: ${perimeter.toFixed(2)}`);
using System;
class Program {
static void Main() {
Console.Write("Enter the length of the first diagonal (d1): ");
double d1 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the length of the second diagonal (d2): ");
double d2 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the side of the rhombus: ");
double side = Convert.ToDouble(Console.ReadLine());
double area = (d1 * d2) / 2;
double perimeter = 4 * side;
Console.WriteLine($"Area of the rhombus: {area:F2}");
Console.WriteLine($"Perimeter of the rhombus: {perimeter:F2}");
}
}