cos()

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:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn C++ on Codecademy