In: Computer Science
Write a program that prompts the user for the length of one side of a triangle and the sizes of the two adjacent angles in degrees and then displays the length of the two other sides and the size of the third angle.
CODE in C++:-
#include <iostream>
#include <cmath>//sine function is defined in this
library.
using namespace std;
#define Pi 3.14159// it is required because angle to sin() function must be in radian
int main()
{
    //since , question doesn't mention the data
types of length and degrees i'll use double type
    double length;
    double angle1, angle2;
   cout<<"Enter the length of a side of triangle:
";
    cin>>length;
    cout<<"Enter the first angle of two
adjacent angles: ";
    cin>>angle1;
    cout<<"Enter the second angle of two
adjacent angles: ";
    cin>>angle2;
    //third angle = 180 - (sum of first two
angles
    double angle3 = (180.0 - (angle1+angle2));
    cout<<"\nThe size of third angle is
"<<angle3;
    /*now to find the length of other two sides
we'll use sine rule defined in trigonometry
    assume that angles provided as input are angles
on side given.
    let unknown sides be a and b.
    applying sine rule
    sin(180-(angle1+angle2))/ length = sin(angle1)/a
= sin(angle2)/b
    assuming a is side opposite to angle1 and b is
opposite to angle2.
    */
    double a , b;//second and third side
    double multipliedToAngles = Pi/ 180.0;
    //the value inside sine() function must be in
radians . so,angles are converted into radians from degrees
    angle1 = multipliedToAngles * angle1;
    angle2 = multipliedToAngles * angle2;
    angle3 = multipliedToAngles * angle3;
    a =
(((sin(angle1))*length)/(sin(angle3)));
    b =
(((sin(angle2))*length)/(sin(angle3)));
    //displaying other sides
    cout<<"\nThe second side length of
triangle is "<<a;
    cout<<"\nThe third side length of triangle
is "<<b;
    return 0;
}
output:-
