Skip to content

Instantly share code, notes, and snippets.

@tabvn
Last active December 6, 2018 06:19
Show Gist options
  • Save tabvn/aff782642814a4e8ea21fa728536ffaa to your computer and use it in GitHub Desktop.
Save tabvn/aff782642814a4e8ea21fa728536ffaa to your computer and use it in GitHub Desktop.
sinx.cpp
#include <iostream>
#include <iomanip>
using namespace std;
#include<iostream>
#include <iomanip>
using namespace std;
double chia(double x, int n){
if(n == 0){
return x;
}
double value = 1;
for (int i = 1; i <= 2*n +1; ++i){
value *= double(x/i);
}
return value;
}
double toRadian(double x){
/* 3.14 -> 180
? <- x
*/
double PI = 3.14159265359;
return double((x/180) *PI);
}
double sinX(double x, double e){
//x = toRadian(x);
double value = 0;
long int i = 0;
double thuong = 0;
while(true){
thuong = chia(x, i);
if(i%2==0){
// chan dau +, le thi mang dau -
value += thuong;
}else{
value -= thuong;
}
if(thuong <= e){
break;
}
i++;
}
return value;
}
int main(){
double x, e;
cin >> x >> e;
cout << fixed << setprecision(4) << sinX(x, e);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment