C++ 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:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C++ on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
- Beginner Friendly.11 hours