Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- cosine_theorem.c
- Law of cosines
- https://www.facebook.com/photo/?fbid=2876673779320015&set=gm.1827487697410072
- c^2 = a^2 + b^2 + 2 * a * b * cos(C)
- c = sqrt( a^2 + b^2 + 2 * a * b * cos(C) )
- C Library <math.h>
- https://www.tutorialspoint.com/c_standard_library/math_h.htm
- https://www.programiz.com/c-programming/library-function/math.h
- https://en.wikipedia.org/wiki/C_mathematical_functions
- https://www.geeksforgeeks.org/c-library-math-h-functions/
- https://en.wikibooks.org/wiki/C_Programming/math.h
- In C Pi is defined in math.h:
- #define M_PI 3.14159265358979323846
- https://www.tutorialspoint.com/c_standard_library/c_function_cos.htm
- https://www.tutorialspoint.com/c_standard_library/c_function_sqrt.htm
- https://www.tutorialspoint.com/c_standard_library/c_function_pow.htm
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- #include <math.h>
- //#define PI 3.14159265
- int main(void)
- {
- double a=3.0, b=4.0, c, gamma_deg, gamma_rad; // gamma is the angle between the sides a and b
- gamma_deg = 90.0; // gamma in degrees
- gamma_rad = (M_PI / 180) * gamma_deg; // gamma in radians
- //gamma_deg = (180 / M_PI) * gamma_deg; // gamma in degrees
- c = sqrt( pow(a,2) + pow(b,2) + 2 * a * b * cos(gamma_rad) );
- printf("\n a = %f \n", a );
- printf("\n b = %f \n", b );
- printf("\n gamma_deg = %f degrees \n", gamma_deg );
- printf("\n gamma_rad = %f radians \n", gamma_rad );
- printf("\n c = %f \n", c );
- printf("\n M_PI = %.16f \n", M_PI );
- return 0;
- } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement