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
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn C++
Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.Beginner Friendly11 hours