Skip to content

Instantly share code, notes, and snippets.

@jeffmarshall
Forked from dianaj/gist:5067043
Last active December 14, 2015 09:49
Show Gist options
  • Save jeffmarshall/5067570 to your computer and use it in GitHub Desktop.
Save jeffmarshall/5067570 to your computer and use it in GitHub Desktop.
public class cosine2 {
public static void main(String [] args) {
double x = Double.parseDouble(args [0]);
x = Math.toRadians (x);
System.out.println (x);
double r = 0.0;
for (int i=0; i<8; i=i+1) {
int n = 2*i;
double p = Math.pow(x,n);
double s = Math.pow((-1),(i));
System.out.println ("multiplier = " + s);
System.out.println("x^"+n+" = " + p);
System.out.print (n + "! = ");
int nf = 1;
while ( n > 1 ) {
nf = nf * n ;
n=n-1;
}
System.out.println (nf);
r = r+(p/nf)*s;
}
System.out.println ("r =" + r + "***");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment