Math Cos Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Cos Function

Math Cos Function

BLUF: Mastering Math Cos Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Cos Function

C++ is renowned for its efficiency. Learn how Math Cos Function enables low-level control and high-performance computing in the tutorial below.

C++ Math cos

The function is utilized to determine the cosine value of an angle specified in radians.

Syntax

Consider a radian 'x'. Syntax would be:

Example

float cos(float x);
float cos(double x);
float cos(long double x);
double cos(integral x);

Note: If the value passed is an integer type, then it is cast to double.

Parameter

x : Value specified in terms of radian.

Return value

It provides the cosine value of an angle within the interval of [-1, 1].

Example 1

Let's examine a basic scenario where the value of x is greater than zero.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    double degree=60;
    double d=60*3.14/180;
    cout<<"Cosine of an angle is : "<<cos(d);
    return 0;
}

Output:

Output

Cosine of an angle is : 0.50046

In this instance, the cos function computes the cosine value of an angle with a measurement of 60 degrees.

Example 2

Let's explore a basic scenario where the value of x is less than zero.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
  double degree= -90;
  double radian=degree*3.14/180;
  cout<<"Cosine of an angle is :"<<cos(radian);
  return 0;
}

Output:

Output

Cosine of an angle is :0.000796327

In this instance, the cos function calculates the cosine of an angle even if the angle is negative, with the property that cos(-x) remains equivalent to cos(x).

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience