Skip to content

Instantly share code, notes, and snippets.

@xbony2
Created June 9, 2019 13:31
Show Gist options
  • Save xbony2/9c318a807e5a3c23307fa469b757a95e to your computer and use it in GitHub Desktop.
Save xbony2/9c318a807e5a3c23307fa469b757a95e to your computer and use it in GitHub Desktop.
class Main {
public static void main(String[] args) {
System.out.println(sin(0.1, 10));
}
public static int factorial(int n){
if(n <= 0)
return 1;
return factorial(n - 1) * n;
}
public static double sin(double x, int n){
double ret = 0.0;
if(n < 1)
return 1;
for(int i = 0; i <= n; i++)
ret += Math.pow(-1, i) * Math.pow(x, 1 + (2 * i))
/ factorial(1 + (2 * i));
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment