Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <math.h>
- using namespace std;
- // Factorial Function
- int factorial(int n){
- if(n == 0){
- return 1;
- }
- else{
- return n * factorial(n-1);
- }
- }
- // Sinus Function
- double sinTaylor(double angle){
- double rads = angle * M_PI / 180;
- double sum = 0;
- int sign = 1;
- for(int i=1; i<=33; i+=2){
- sum += sign * pow(rads, i) / factorial(i);
- sign = -sign;
- }
- return sum;
- }
- // Cosinus Function
- double cosTaylor(double angle){
- double rads = angle * M_PI / 180;
- double sum = 0;
- int sign = 1;
- for(int i=0; i<=32; i+=2){
- sum += sign * pow(rads, i) / factorial(i);
- sign = -sign;
- }
- return sum;
- }
- int main()
- {
- cout << "sin(0) = " << sin(0) << " = " << sinTaylor(0) << endl;
- cout << "sin(15) = " << sin(15* M_PI / 180) << " = " << sinTaylor(15) << endl;
- cout << "sin(30) = " << sin(30* M_PI / 180) << " = " << sinTaylor(30) << endl;
- cout << "sin(45) = " << sin(45* M_PI / 180) << " = " << sinTaylor(45) << endl;
- cout << "sin(60) = " << sin(60* M_PI / 180) << " = " << sinTaylor(60) << endl;
- cout << "sin(75) = " << sin(75* M_PI / 180) << " = " << sinTaylor(75) << endl;
- cout << "sin(90) = " << sin(90* M_PI / 180) << " = " << sinTaylor(90) << endl;
- cout << endl;
- cout << "cos(0) = " << cos(0) << " = " << cosTaylor(0) << endl;
- cout << "cos(15) = " << cos(15* M_PI / 180) << " = " << cosTaylor(15) << endl;
- cout << "cos(30) = " << cos(30* M_PI / 180) << " = " << cosTaylor(30) << endl;
- cout << "cos(45) = " << cos(45* M_PI / 180) << " = " << cosTaylor(45) << endl;
- cout << "cos(60) = " << cos(60* M_PI / 180) << " = " << cosTaylor(60) << endl;
- cout << "cos(75) = " << cos(75* M_PI / 180) << " = " << cosTaylor(75) << endl;
- cout << "cos(90) = " << cos(90* M_PI / 180) << " = " << cosTaylor(90) << endl;
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement