Saturday, January 11, 2025
Google search engine
HomeData Modelling & AILength of remaining two sides of a Triangle from a given side...

Length of remaining two sides of a Triangle from a given side and its adjacent angles

Given the length of a side a of a triangle and its adjacent angles B and C, the task is to find the remaining two sides of the triangle. 

Input: a = 5, B = 62.2, C = 33.5 
Output: 4.44, 2.77 
Explanation 
The remaining two sides of the triangle are b = 4.44488228556699 and c = 2.7733977979419038
Input: a = 12, B = 60, C = 30 
Output: 10.39, 5.99 
Explanation 
The remaining two sides of the triangle are b = 10.392304845413264 and c = 5.999999999999999 
 

Approach:  

  1. The remaining angle can be calculated by the angle sum theorem in a triangle:
  2. The other two sides of triangle can be computed using sine formula:

Below is the implementation of the above approach: 
 

C++




// C++ program for above approach
#include<bits/stdc++.h>
using namespace std;
 
// Function for computing other
// 2 side of the triangle
void findSide(float a, float B, float C)
{
     
    // Computing angle C
    float A = 180 - C - B;
     
    // Converting A in to radian
    float radA = M_PI * (A / 180);
     
    // Converting B in to radian
    float radB = M_PI * (B / 180);
     
    // Converting C in to radian
    float radC = M_PI * (C / 180);
     
    // Computing length of side b
    float b = a / sin(radA) * sin(radB);
     
    // Computing length of side c
    float c = a / sin(radA) * sin(radC);
     
    cout << fixed << setprecision(15) << b << " ";
    cout << fixed << setprecision(15) << c;
}
 
// Driver code
int main()
{
    int a = 12, B = 60, C = 30;
     
    // Calling function
    findSide(a, B, C);
}
 
// This code is contributed by ishayadav181


Java




// Java program for above approach
import java.util.*;
 
class GFG{
 
// Function for computing other
// 2 side of the triangle
static void findSide(double a, double B,
                     double C)
{
     
    // Computing angle C
    double A = 180 - C - B;
     
    // Converting A in to radian
    double radA = (Math.PI * (A / 180));
     
    // Converting B in to radian
    double radB = (Math.PI * (B / 180));
     
    // Converting C in to radian
    double radC = (Math.PI * (C / 180));
     
    // Computing length of side b
    double b = (a / Math.sin(radA) *
                    Math.sin(radB));
     
    // Computing length of side c
    double c = (a / Math.sin(radA) *
                    Math.sin(radC));
     
    System.out.printf("%.15f", b);
    System.out.printf(" %.15f", c);
}
 
// Driver code
public static void main(String[] args)
{
    int a = 12, B = 60, C = 30;
     
    // Calling function
    findSide(a, B, C);
}
}
 
// This code is contributed by Amit Katiyar


Python3




# Python3 program for above approach
import math
 
# Function for computing other
# 2 side of the triangle
def findSide(a, B, C):
 
    # computing angle C
    A = 180-C-B
 
    # converting A in to radian
    radA = math.pi *(A / 180)
 
    # converting B in to radian
    radB = math.pi *(B / 180)
 
    # converting C in to radian
    radC = math.pi *(C / 180)
 
    # computing length of side b
    b = a / math.sin(radA)*math.sin(radB)
 
    # computing length of side c
    c = a / math.sin(radA)*math.sin(radC)
 
    return b, c
 
# driver program
a = 12
B = 60
C = 30
 
# calling function
b, c = findSide(a, B, C)
print(b, c)


C#




// C# program for above approach
using System;
class GFG{
 
// Function for computing other
// 2 side of the triangle
static void findSide(float a,
                     double B, double C)
{   
  // Computing angle C
  double A = 180 - C - B;
 
  // Converting A in to radian
  double radA = (Math.PI * (A / 180));
 
  // Converting B in to radian
  double radB = (Math.PI * (B / 180));
 
  // Converting C in to radian
  double radC = (Math.PI * (C / 180));
 
  // Computing length of side b
  double b = (a / Math.Sin(radA) *
              Math.Sin(radB));
 
  // Computing length of side c
  double c = (a / Math.Sin(radA) *
              Math.Sin(radC));
 
  Console.Write("{0:F15}", b);
  Console.Write("{0:F15}", c);
}
 
  // Driver code
  public static void Main(String[] args)
  {
    int a = 12, B = 60, C = 30;
 
    // Calling function
    findSide(a, B, C);
  }
}
 
// This code is contributed by 29AjayKumar


Javascript




<script>
// Javascript program for above approach
 
// Function for computing other
// 2 side of the triangle
function findSide(a, B, C)
{
     
    // Computing angle C
    var A = 180 - C - B;
     
    // Converting A in to radian
    var radA = Math.PI * (A / 180);
     
    // Converting B in to radian
    var radB = Math.PI * (B / 180);
     
    // Converting C in to radian
    var radC = Math.PI * (C / 180);
     
    // Computing length of side b
    var b = a / Math.sin(radA) * Math.sin(radB);
     
    // Computing length of side c
    var c = a / Math.sin(radA) * Math.sin(radC);
     
    document.write( b + " ");
    document.write( c);
}
 
// Driver code
var a = 12, B = 60, C = 30;
 
// Calling function
findSide(a, B, C);
 
</script>


Output: 

10.392304845413264 5.999999999999999

 

Time Complexity: O(1) 
Auxiliary Space: O(1)  

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Recent Comments