Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- double Sin(double);
- double Fact(double);
- 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) << Sin(radians) << endl;
- }
- double Sin(double number)
- {
- double sin = 0;
- cout << fixed;
- for(double i = 0; i < 10; i++)
- {
- sin += ((pow(-1, i))*(pow(number,(2*i) + 1)))/(Fact((2*i) + 1));
- //cout << sin << endl;
- }
- sin = abs(sin);
- sin = sin*sin; //without this it would only print sine
- return sin;
- }
- double Fact(double number) //factoriel algorithm function
- {
- double counter = 1;
- for(double i = 1; i <= number; i++)
- {
- counter = counter * i;
- if(counter >= INT_MAX)
- {
- break;
- }
- }
- return counter;
- }
- double ConvertTo(double number) //converts degrees to radians
- {
- int num = (int)number/180.0;
- number = number - (num*180);
- number = (double)number;
- return number;
- }
- /*
- -------------------------------------------------------------------------------------------------------------------------------------
- -------------------------------------------------------------------------------------------------------------------------------------
- Calculus II Math Exercise - Degrees to Arc Length
- -------------------------------------------------------------------------------------------------------------------------------------
- -------------------------------------------------------------------------------------------------------------------------------------
- */
Add Comment
Please, Sign In to add comment