 cos function in c programming

## 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;
}``````

``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.

Cos() Man Page.

## 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);``````

## 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);``````

## 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);``````