Upload files to "OOP/Java/Lab/Week3"

This commit is contained in:
Aadit Agrawal 2024-08-10 11:23:06 +05:30
parent ff230bd039
commit 18c9a0ecff

View File

@ -14,12 +14,12 @@ public class SqInvAndSinCalc {
System.out.println("Enter the input in degrees for the Sine function:"); System.out.println("Enter the input in degrees for the Sine function:");
double y = sc.nextDouble(); double y = sc.nextDouble();
double x = (y) * (3.1415926 / 180.0); double x = y * (3.1415926 / 180.0);
double sinx = x; sinx = x;
int n = 1; int n = 1;
for (int i = 1; i <= terms; i++) { for (int i = 1; i <= terms; i++) {
double term = pow(-1, n) * pow(x, 2 * n + 1) / tgamma(2 * n + 1); double term = Math.pow(-1, n) * Math.pow(x, 2 * n + 1) / factorial(2 * n + 1);
sinx += term; sinx += term;
n++; n++;
} }
@ -28,4 +28,12 @@ public class SqInvAndSinCalc {
System.out.println("The sum is " + sum); System.out.println("The sum is " + sum);
} }
public static double factorial(int n) {
double result = 1;
for (int i = 2; i <= n; i++) {
result *= i;
}
return result;
}
} }