Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <climits>
- #include <iomanip>
- using namespace std;
- double Cos(double);
- double Fact(int);
- double ConvertTo(double);
- int main()
- {
- double degrees;
- cin >> degrees;
- if(degrees > 180)
- {
- degrees = ConvertTo(degrees);
- }
- if(degrees < 0)
- {
- degrees = degrees*(-1);
- }
- double radians = (degrees/180)*3.14159;
- cout << setprecision(7) << Cos(radians) << endl;
- }
- double Cos(double number)
- {
- double cos = 0;
- cout << fixed;
- for(int i = 0; i <= 18; i++)
- {
- cos += (pow(-1,i)*pow(number,(2*i)))/Fact(2*i);
- }
- return cos;
- }
- double Fact(int num) //factorial algorithm
- {
- double counter = 1;
- for(double i = 1; i <= num; i++)
- {
- counter = counter * i;
- if(counter >= INT_MAX)
- {
- break;
- }
- }
- return counter;
- }
- double ConvertTo(double number) //converts degrees to radians
- {
- int num = number/180.0;
- number = number - (int)(num*180);
- number = (double)number;
- return number;
- }
- /*
- --------------------------------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------------------------------
- Calculus II Math Exercise - Degrees to Arc Length
- --------------------------------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------------------------------
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement