The cos Function in C programming is one of the Math Library Function, which is used to calculate the Trigonometry Cosine value for the specified expression.
In this article we will show you, How to use this COS function with example.
TIP : Please refer ACOS Function article to calculate the Arc Cosine of specified expression.
Syntax of a COS Function in C
Before we get into to the syntax, Let us see the mathematical formula behind this C Trigonometry Cosine function:
cos(x) = Length of the Adjacent Side / Length of the Hypotenuse
The basic syntax of the cos inĀ C Programming is as shown below.
double cos(double number);
NOTE: The COS function in C will return the value between -1 and 1.
COS Function in C Example
The cos Function in math library allows you to find the trigonometry Cosine for the specified values.
This program, ask the user to enter his/her own value, and then it will find the cosine value of the user specified one
/* Example for COS Function in C Programming */ #include <stdio.h> #include <math.h> int main() { double cosValue, number; printf(" Please Enter the Value to calculate Cosine : "); scanf("%lf", &number); cosValue = cos(number); printf("\n Cosine value of %lf = %f ", number, cosValue); return 0; }
OUTPUT
C COS Function Example 2
In this c cos function example, we are allowing the user to enter the value in degrees, and then we are converting the degrees to Radians. And finally, we are finding the cosine value of the radian
/* Example for COS Function in C Programming */ #include <stdio.h> #include <math.h> #define PI 3.14 int main() { double cosValue, radianVal, degreeVal; printf(" Please Enter an Angle in degrees : "); scanf("%lf", °reeVal); // Convert Dgree Value to Radian radianVal = degreeVal * (PI/180); cosValue = cos(radianVal); printf("\n Cosine value of %f = %f ", degreeVal, cosValue); return 0; }
OUTPUT
Thank You for Visiting Our Blog