Created
June 9, 2019 13:31
-
-
Save xbony2/9c318a807e5a3c23307fa469b757a95e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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