Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ <cmath> cos() function is used to return trigonometric cosine of an angle (angle should be in radians).

Syntax

double cos (double x);
float cos (float x);
long double cos (long double x);
double cos (double x);
float cos (float x);
long double cos (long double x);
//additional overloads for integral types
double cos (T x);           

Parameters

x Specify the angle in radian.

Return Value

Returns the trigonometric cosine of an angle.

Example:

In the below example, cos() function is used to find out the trigonometric cosine of an angle.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  //M_PI - value of PI from math.h
  cout<<cos(M_PI/6)<<"\n";
  cout<<cos(M_PI/4)<<"\n";
  cout<<cos(M_PI/3)<<"\n";
  return 0;
}

The output of the above code will be:

0.866025
0.707107
0.5

❮ C++ <cmath> Library