Dada la longitud de la diagonal ‘d1’ de un rombo y un lado ‘a’, la tarea es encontrar el área de ese rombo.
Un rombo es un polígono que tiene 4 lados iguales en el que ambos lados opuestos son paralelos y los ángulos opuestos son iguales.
Ejemplos:
Input: d = 15, a = 10 Output: 99.21567416492215 Input: d = 20, a = 18 Output: 299.3325909419153
Acercarse:
- Obtener la diagonal ‘d1’ y el lado ‘a’ del rombo
- Lo sabemos,
- Pero como no conocemos la otra diagonal d2, no podemos usar esta fórmula todavía
- Así que primero encontramos la segunda diagonal d2 con la ayuda de d1 y a
- Ahora podemos usar la fórmula del área para calcular el área del rombo
C++
// C++ program to calculate the area of a rhombus // whose one side and one diagonal is given #include<bits/stdc++.h> using namespace std; // function to calculate the area of the rhombus double area(double d1, double a) { // Second diagonal double d2 = sqrt(4 * (a * a) - d1 * d1); // area of rhombus double area = 0.5 * d1 * d2; // return the area return area; } // Driver code int main() { double d = 7.07; double a = 5; printf("%0.8f", area(d, a)); } // This code is contributed by Mohit Kumar
Java
// Java program to calculate the area of a rhombus // whose one side and one diagonal is given class GFG { // function to calculate the area of the rhombus static double area(double d1, double a) { // Second diagonal double d2 = Math.sqrt(4 * (a * a) - d1 * d1); // area of rhombus double area = 0.5 * d1 * d2; // return the area return area; } // Driver code public static void main (String[] args) { double d = 7.07; double a = 5; System.out.println(area(d, a)); } } // This code is contributed by AnkitRai01
Python3
# Python program to calculate # the area of a rhombus # whose one side and # one diagonal is given # function to calculate # the area of the rhombus def area(d1, a): # Second diagonal d2 = (4*(a**2) - d1**2)**0.5 # area of rhombus area = 0.5 * d1 * d2 # return the area return(area) # driver code d = 7.07 a = 5 print(area(d, a))
C#
// C# program to calculate the area of a rhombus // whose one side and one diagonal is given using System; class GFG { // function to calculate the area of the rhombus static double area(double d1, double a) { // Second diagonal double d2 = Math.Sqrt(4 * (a * a) - d1 * d1); // area of rhombus double area = 0.5 * d1 * d2; // return the area return area; } // Driver code public static void Main (String []args) { double d = 7.07; double a = 5; Console.WriteLine(area(d, a)); } } // This code is contributed by Arnab Kundu
Javascript
<script> // javascript program to calculate the area of a rhombus // whose one side and one diagonal is given // function to calculate the area of the rhombus function area(d1 , a) { // Second diagonal var d2 = Math.sqrt(4 * (a * a) - d1 * d1); // area of rhombus var area = 0.5 * d1 * d2; // return the area return area; } // Driver code var d = 7.07; var a = 5; document.write(area(d, a)); // This code is contributed by 29AjayKumar </script>
Producción:
24.999998859949972
Complejidad de tiempo: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por Atul_kumar_Shrivastava y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA