cos()

The cos() returns the cosine of an argument given in radians.

Syntax

std::cos(n)

Example 1

Use cos() to return the cosine of 3.1416 radians:

#include <iostream>
#include <cmath>
int main()
{
double x = 3.1416;
double result;
result = std::cos(x);
std::cout << "The cosine of " << x << " radians is " << result << "\n";
// Output: The cosine of 3.1416 radians is -1
}

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn C++ on Codecademy