/* The law of cosines is a very important formula in geometry. If you know the length of 2 sides of a triangle and the angle between those sides, then you can use the law of cosines to find the length of the third side of the triangle. The law is stated as follows: c^2 = a^2 + b^2 - 2*a*b*cos(alpha) Where c is the length of the third side, and alpha is the angle between sides a and b. Your assignment is to write a program that gets from the user: -the length of two sides of the triangle -the angle between the two sides, in degrees You are to use the law of cosines to calculate the length of the third side, and then print the result to the console. The library contains the following useful things: -square root [sqrt(x) returns the square root of x] -power [pow(x, y) returns x raised to the power y] -cosine [cos(x) returns the cosine of x] -M_PI [the ratio of the circumfrence of a circle to its radius, roughly 3.14159...] Be warned however, that the cos function in the math library takes an angle measured in RADIANS, and you are reading the angle measured in DEGREES. To convert, use the formula: angleInRadians = pi * (angleInDegrees / 180.0) Make sure that all variables are of type double, and print the result to an accuracy of 2 decimal places. It might be helpful to make a separate function to calculate the result using the law of cosines. ============= START OF SAMPLE RUN ======================= Enter length of side a: 4.5 Enter length of side b: 9.7 Enter angle between a and b, in degrees: 52.5 The length of side c is 7.82. ============= END OF SAMPLE RUN ======================= */ #include #include #include double degrees2radians(double degrees) { return (degrees / 180.0) * M_PI; } double calc_third_side(double sideA, double sideB, double abAngle) { double angleInRadians = degrees2radians(abAngle); return sqrt(sideA*sideA + sideB*sideB- 2*sideA*sideB*cos(angleInRadians)); } int main(int argc, char* argv[]) { double sideA=0; double sideB=0; double abAngle=0; double sideC=0; printf("Enter the length of side A: "); scanf("%lf", &sideA); printf("Enter the length of side B: "); scanf("%lf", &sideB); printf("Enter the angle between A and B (in degrees): "); scanf("%lf", &abAngle); sideC = calc_third_side(sideA, sideB, abAngle); printf("\nThe length of side C is %.2f.\n", sideC); system("pause"); return 0; }