Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to use trigonometric function in C Language ?

+4 votes
asked Apr 15 by BIDESH MAJUMDAR (160 points)

1 Answer

+1 vote
answered Apr 15 by Aditya Dwivedi (220 points)
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 &lt;math.h&gt;</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 &lt;stdio.h&gt;
#include &lt;math.h&gt;

#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!
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...