I have Written a code for sine function but it is not much accurate
I have written a code for PI() and sin() function but it is not much accurate I want to make it more accurate can anybody tell how can I make it more accurate.
Also I dont want to use constant value of pi. I want to find it out using function to the highest accuracy.
Following is the code
#include <iostream>
#include <string>
using namespace std;
double factorial (int a);
double power (double b, int power);
double MySin(double c, int Accuracy = 100);
double MyPi(double accuracy = 50);
int main (void){
//Comment Out below code for testing factorial function
// int MyNumber;
//cout << "Enter the number for which you want factorial to find out?\n";
//cin >> MyNumber;
//cout << "Factorial of " << MyNumber << " is " << factorial(MyNumber) << endl;
//
//
//getchar();
//Comment out below code for testing power function
//double MyNumber;
//int NumPower;
//cout << "Enter the number" << endl;
//cin >> MyNumber;
//cout << "\nEnter the power" << endl;
//cin >> NumPower;
//cout << power(MyNumber,NumPower);
//Comment out below code for testing Sine function
//cout << MySin(30,1000);
//Comment out below code for testing value of pi
//cout << MyPi(100000) << "End of line";
}
double MyPi(double accuracy){
double result = 0;
for (double index = 1+accuracy*2; index >= 3; index-=2){
result = 2+power(index,2)/result;
}
return 4/(1+(1/result));
}
double MySin(double c, int Accuracy){
c=c*MyPi(1000)/180;
double result = c;
int Minus = -1;
for (int index = 3; index < Accuracy; index+=2 ){
result = result + Minus * power(c,index)/factorial(index);
Minus*=-1;
}
return result;
}
double power (double b, int power){
double result = 1;
while (power>0){
result *= b;
power--;
}
return result;
}
double factorial (int a){
double result;
if(a==1){
return 1;
}else{
result = a * factorial(a-1);
}
return result;
}