<code><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><stdio.h></span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><math.h></span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> PI 3.141592654</span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>
</span>{
<span class="hljs-keyword">double</span> arg = <span class="hljs-number">30</span>, result;
<span class="hljs-comment">// Converting to radian</span>
arg = (arg * PI) / <span class="hljs-number">180</span>;
result = <span class="hljs-built_in">cos</span>(arg);
<span class="hljs-built_in">printf</span>(<span class="hljs-string">"cos of %.2lf radian = %.2lf"</span>, arg, result);
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}</code>
Shathana. S.R. Answered question May 27, 2023
The given code is a C program that calculates the cosine of an angle in radians. Here’s a breakdown of the code:
- The program includes the necessary header files:
stdio.hfor input/output operations andmath.hfor mathematical functions. - The constant
PIis defined with an approximate value of 3.141592654. - The
mainfunction is defined with a return type ofintand no parameters. - Inside the
mainfunction:- A variable
argof typedoubleis declared and assigned a value of 30, representing the angle in degrees. - The value of
argis converted to radians by multiplying it withPIand dividing by 180. - The
cosfunction from themathlibrary is used to calculate the cosine ofarg, and the result is stored in theresultvariable. - The
printffunction is used to display the value ofargandresult, formatted with two decimal places. - The
mainfunction returns 0, indicating successful program execution.
- A variable
When you run this program, it will output the cosine of 30 degrees (converted to radians) as follows:
cos of <span class="hljs-number">0.52</span> radian = <span class="hljs-number">0.87</span>
Please note that the cos function from the math library expects the angle to be in radians, so the conversion from degrees to radians is necessary.
Annie Sanjana Answered question May 27, 2023
