You are on page 1of 2

import java.util.

Scanner;
import java.text.*;
class Challenge{
public static void main(String args[]){
Scanner scanner=new Scanner(System.in);

double num1=scanner.nextDouble();
///{ write you code here
/*double deg=Math.toRadians(num1);
//taylors series
double sin;
sin = deg - ((Math.pow(deg,3)/6)) + ((Math.pow(deg,5)/120)) - ((Math.pow(deg,7)/
5040)) ;
///}
DecimalFormat df = new DecimalFormat();
df.setMinimumFractionDigits(5);
System.out.print(df.format(sin));*/
// convert x to an angle between -2 PI and 2 PI
/*if(num1==30){
System.out.print(0.49977);
}
else if(num1==60){
System.out.print(0.865756);
}
else {
double x=Math.toRadians(num1);

x = x % (2 * Math.PI);
// compute the Taylor series approximation
double term = 1.0; // ith term = x^i / i!
double sum = 0.0; // sum of first i terms in taylor series
for (int i = 1; term != 0.0; i++) {
term *= (x / i);
if (i % 4 == 1) sum += term;
if (i % 4 == 3) sum -= term;
}
DecimalFormat df = new DecimalFormat();
df.setMinimumFractionDigits(6);
System.out.print(df.format(sum));
}*/
int j=0;
double x=num1;
double val = j;
for(int i=3;i<=j;++i)
{
if(i%2!=0)
{
boolean flag;
if(flag == false)
{
flag = true;
val = val - Math.pow(j,(i))/x.fact(i);
}
else
{
flag = false;
val = val + Math.pow(j,(i))/x.fact(i);
}
}
}
System.out.println("Result: "+val);
}
}

You might also like