To use trigonometric functions in C, you need to include the math.h header file. Here's a quick guide:
<b>1. Include the header:</b>
<pre><code>#include <math.h></code></pre>
<b>2. Available trigonometric functions:</b>
- <b>sin(x)</b> - returns sine of x (x in radians)
- <b>cos(x)</b> - returns cosine of x (x in radians)
- <b>tan(x)</b> - returns tangent of x (x in radians)
- <b>asin(x)</b> - returns arc sine of x
- <b>acos(x)</b> - returns arc cosine of x
- <b>atan(x)</b> - returns arc tangent of x
<b>3. Important note:</b> All trigonometric functions in C work with <b>radians</b>, not degrees. To convert degrees to radians, use: <code>radians = degrees * (PI / 180.0)</code>
<b>4. Example code:</b>
<pre><code>#include <stdio.h>
#include <math.h>
#define PI 3.14159265359
int main() {
double angle_deg = 45.0;
double angle_rad = angle_deg * (PI / 180.0);
printf("sin(%.2f) = %.4f\n", angle_deg, sin(angle_rad));
printf("cos(%.2f) = %.4f\n", angle_deg, cos(angle_rad));
printf("tan(%.2f) = %.4f\n", angle_deg, tan(angle_rad));
return 0;
}</code></pre>
<b>5. Compiling with math library:</b> When using GCC, link the math library with the -lm flag:
<pre><code>gcc program.c -o program -lm</code></pre>
This should get you started with trigonometric functions in C!