Dados dos números enteros A , B que representan la longitud de dos lados de un triángulo y un número K que representa el ángulo entre ellos en radianes, la tarea es calcular el área del triángulo a partir de la información dada.
Ejemplos:
Entrada: a = 9, b = 12, K = 2
Salida: 49,1
Explicación:
Área del triángulo = 1 / 2 * (9 * 12 * Sin 2) = 35,12
Entrada: A = 2, B = 4, K = 1
Salida : 3.37
Enfoque:
Considere el siguiente triángulo ABC con lados A , B , C y un ángulo K entre los lados A y B .
Entonces, el área del triángulo se puede calcular usando la fórmula Lado-Ángulo-Lado :
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program to calculate // the area of a triangle when // the length of two adjacent // sides and the angle between // them is provided #include <bits/stdc++.h> using namespace std; float Area_of_Triangle(int a, int b, int k) { float area = (float)((1 / 2.0) * a * b * (sin(k))); return area; } // Driver Code int main() { int a = 9; int b = 12; int k = 2; // Function Call float ans = Area_of_Triangle(a, b, k); // Print the final answer cout << ans << endl; } // This code is contributed by Ritik Bansal
Java
// Java program to calculate // the area of a triangle when // the length of two adjacent // sides and the angle between // them is provided class GFG{ // Function to return the area of // triangle using Side-Angle-Side // formula static float Area_of_Triangle(int a, int b, int k) { float area = (float)((1 / 2.0) * a * b * Math.sin(k)); return area; } // Driver Code public static void main(String[] args) { int a = 9; int b = 12; int k = 2; // Function Call float ans = Area_of_Triangle(a, b, k); // Print the final answer System.out.printf("%.1f",ans); } } // This code is contributed by sapnasingh4991
Python3
# Python3 program to calculate # the area of a triangle when # the length of two adjacent # sides and the angle between # them is provided import math # Function to return the area of # triangle using Side-Angle-Side # formula def Area_of_Triangle(a, b, k): area =(1 / 2) * a * b * math.sin(k) return area # Driver Code a = 9 b = 12 k = 2 # Function Call ans = Area_of_Triangle(a, b, k) # Print the final answer print(round(ans, 2))
C#
// C# program to calculate // the area of a triangle when // the length of two adjacent // sides and the angle between // them is provided using System; class GFG{ // Function to return the area of // triangle using Side-Angle-Side // formula static float Area_of_Triangle(int a, int b, int k) { float area = (float)((1 / 2.0) * a * b * Math.Sin(k)); return area; } // Driver Code public static void Main(String[] args) { int a = 9; int b = 12; int k = 2; // Function Call float ans = Area_of_Triangle(a, b, k); // Print the readonly answer Console.Write("{0:F1}", ans); } } // This code is contributed by sapnasingh4991
Javascript
<script> // javascript program to calculate // the area of a triangle when // the length of two adjacent // sides and the angle between // them is provided// Function to return the area of // triangle using Side-Angle-Side // formula function Area_of_Triangle(a , b, k) { var area = ((1 / 2.0) * a * b * Math.sin(k)); return area; } // Driver Code var a = 9; var b = 12; var k = 2; // Function Call var ans = Area_of_Triangle(a, b, k); // Print the final answer document.write(ans.toFixed(1)); // This code is contributed by 29AjayKumar </script>
49.1
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por divyamohan123 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA