What is cos in c programming?
cos in c is a mathematical function which is used to find cosine of a given number.
This function is defined in math.h header file.
Prototype
#include<math.h>
double cos(double y);
Parameters
cos function takes floating point value as angle in radians.
Return value
This function returns cosine of a given number.
Example program for cos in c
#include <stdio.h>
#include <math.h>
#define PI 3.14
int main()
{
double x, res, val1;
x=35.0;
val1=PI/180;
res=cos(x*val1);
printf("The cosine of %lf is %lf degrees", x, res);
return 0;
}
While using gcc use below command to add math header.
gcc file_name.c -lm
Code explanation
The variable val1 is converted in terms of degrees and passed along with the input value to the cos function. The cosine value is being printed onto the console.
Difference between cos and cosh in c?
cos in c is a mathematical function that is used to find the cosine of a given number. cosh in c is used to find the hyperbolic cosine of a given number.
Prototypes are as follows
double cos(double y);
double cosh(double y);
cos in c | cosh in c |
Used to find cosine of a given number. | Used to find hyperbolic cosine of a given number. |
double cos(double y); | double cosh(double y); |
Difference between cos and sin in c
cos in c is a mathematical function that is used to find the cosine of a given number. sin is a mathematical function that is used to find the sine of a given number.
Prototypes are as follows
double cos(double y);
double sin(double y);
cos in c | sin in c |
Used to find cosine of a given number. | Used to find sine of a given number. |
double cos(double y); | double sin(double y); |
Difference between cos and tan in c
cos in c is a mathematical function that is used to find the cosine of a given number. tan is a mathematical function that is used to find the tangent of a given number.
Prototypes are as follows
double cos(double y);
double tan(double y);
cos in c | tan in c |
Used to find cosine of a given number. | Used to find tangent of a given number. |
double cos(double y); | double tan(double y); |
People also ask for
What is the cos equation?
It is a trigonometric function. cos of an angle m is the length of the adjacent side divided by the length of the hypotenuse.
What type of errors one can find if cos in c fails?
The error one can find if cos in c fail is domain error.