 # cosine_theorem.c

Feb 21st, 2021
707
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /*
2.
3.     cosine_theorem.c
4.
5.     Law of cosines
6.
8.
9.     c^2 = a^2 + b^2 + 2 * a * b * cos(C)
10.
11.     c  = sqrt( a^2 + b^2 + 2 * a * b * cos(C) )
12.
13.
14.     C Library  <math.h>
15. https://www.tutorialspoint.com/c_standard_library/math_h.htm
16. https://www.programiz.com/c-programming/library-function/math.h
17. https://en.wikipedia.org/wiki/C_mathematical_functions
18. https://www.geeksforgeeks.org/c-library-math-h-functions/
19. https://en.wikibooks.org/wiki/C_Programming/math.h
20.
21. In C Pi is defined in math.h:
22. #define M_PI 3.14159265358979323846
23.
24. https://www.tutorialspoint.com/c_standard_library/c_function_cos.htm
25. https://www.tutorialspoint.com/c_standard_library/c_function_sqrt.htm
26. https://www.tutorialspoint.com/c_standard_library/c_function_pow.htm
27.
28.
29.     You can find all my C programs at Dragan Milicev's pastebin:
30.
31.     https://pastebin.com/u/dmilicev
32.
33. */
34.
35. #include <stdio.h>
36. #include <math.h>
37.
38. //#define PI 3.14159265
39.
40. int main(void)
41. {
42.     double a=3.0, b=4.0, c, gamma_deg, gamma_rad;   // gamma is the angle between the sides a and b
43.
44.     gamma_deg = 90.0;                               // gamma in degrees
45.
46.     gamma_rad = (M_PI / 180) * gamma_deg;           // gamma in radians
47.     //gamma_deg = (180 / M_PI) * gamma_deg;         // gamma in degrees
48.
49.     c  = sqrt( pow(a,2) + pow(b,2) + 2 * a * b * cos(gamma_rad) );
50.
51.     printf("\n a = %f \n", a );
52.     printf("\n b = %f \n", b );
53.
54.     printf("\n gamma_deg = %f degrees \n", gamma_deg );