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,18 +14,26 @@ public class SqInvAndSinCalc {
System.out.println("Enter the input in degrees for the Sine function:");
double y = sc.nextDouble();
double x = (y) * (3.1415926 / 180.0);
double sinx = x;
double x = y * (3.1415926 / 180.0);
sinx = x;
int n = 1;
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;
n++;
}
System.out.println("The value of Sin("+x+") is: "+sinx);
System.out.println("The value of Sin(" + x + ") is: " + sinx);
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;
}
}