Given two integers A, B representing the length of two sides of a triangle and an integer K representing the angle between them in radian, the task is to calculate the area of the triangle from the given information.
Examples:
Input: a = 9, b = 12, K = 2
Output: 49.1
Explanation:
Area of triangle = 1 / 2 * (9 * 12 * Sin 2) = 35.12
Input: A = 2, B = 4, K = 1
Output: 3.37
Approach:
Consider the following triangle ABC with sides A, B, C, and an angle K between sides A and B.

Then, the area of the triangle can be calculated using the Side-Angle-Side formula:

Below is the implementation of the above approach:
C++
#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;
}
int main()
{
int a = 9;
int b = 12;
int k = 2;
float ans = Area_of_Triangle(a, b, k);
cout << ans << endl;
}
|
Java
class GFG{
static float Area_of_Triangle( int a, int b,
int k)
{
float area = ( float )(( 1 / 2.0 ) *
a * b * Math.sin(k));
return area;
}
public static void main(String[] args)
{
int a = 9 ;
int b = 12 ;
int k = 2 ;
float ans = Area_of_Triangle(a, b, k);
System.out.printf( "%.1f" ,ans);
}
}
|
Python3
import math
def Area_of_Triangle(a, b, k):
area = ( 1 / 2 ) * a * b * math.sin(k)
return area
a = 9
b = 12
k = 2
ans = Area_of_Triangle(a, b, k)
print ( round (ans, 2 ))
|
C#
using System;
class GFG{
static float Area_of_Triangle( int a, int b,
int k)
{
float area = ( float )((1 / 2.0) *
a * b * Math.Sin(k));
return area;
}
public static void Main(String[] args)
{
int a = 9;
int b = 12;
int k = 2;
float ans = Area_of_Triangle(a, b, k);
Console.Write( "{0:F1}" , ans);
}
}
|
Javascript
<script>
function Area_of_Triangle(a , b, k)
{
var area = ((1 / 2.0) *
a * b * Math.sin(k));
return area;
}
var a = 9;
var b = 12;
var k = 2;
var ans = Area_of_Triangle(a, b, k);
document.write(ans.toFixed(1));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)