Last active
September 25, 2016 21:13
-
-
Save jclosure/3a3e9f12e3882e1f2b48cddd85808083 to your computer and use it in GitHub Desktop.
Convert Degrees to Radians (C++)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <math.h> // for sin() and cos() | |
| void getSinCos(double degrees, double &sinOut, double &cosOut) | |
| { | |
| // sin() and cos() take radians, not degrees, so we need to convert | |
| static const double pi = 3.14159265358979323846; // the value of pi | |
| double radians = degrees * pi / 180.0; | |
| sinOut = sin(radians); | |
| cosOut = cos(radians); | |
| } | |
| int main() | |
| { | |
| double sin(0.0); | |
| double cos(0.0); | |
| // getSinCos will return the sin and cos in variables sin and cos | |
| getSinCos(30.0, sin, cos); | |
| std::cout << "The sin is " << sin << '\n'; | |
| std::cout << "The cos is " << cos << '\n'; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment