cos()

GaVi-_'s avatar
Published Jul 20, 2021Updated Jul 31, 2023
Contribute to Docs

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

Syntax

std::cos(n)

Example

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";
}

This results in the following output:

The cosine of 3.1416 radians is -1

Codebyte Example

Use cos() to return the cosine of 25 degrees:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn C++ on Codecademy