package cosx;
import java.util.Scanner;
public class cosx2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the degree: ");
double degree = input.nextDouble();
double radian = getRadian(degree);
calculateCos(input, radian,degree);
}
public static double getRadian(double x) {
return x = (Math.PI/180)*x;
}
private static void calculateCos(Scanner std, double rad, double deg) {
System.out.print("How many terms do you want to calculate the cos: ");
int terms = std.nextInt();
double top;
double bottom;
double sum=0;
for(int i = 0; i<= terms; ++i){
top = Math.pow(-1, i);
bottom =1;
int repeat = 2*i+1;
for(int j = 1; j <= repeat; ++j){
bottom *= j;
}
if(i%2 == 0)
sum += (top/bottom);
else
sum -= (top/bottom);
}
System.out.printf("The sin (%.1f", deg);
System.out.printf(") is %.6f", sum);
}
}