# q3 QuÄ±z - x double sum= 0.0 for int n=;n<= 100;n sum...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
File: /home/mentalx/Desktop/kmu255_codes/quiz3.java Page 1 of 2 class quiz3 { public static double us( double x, int y) { double result= 1 ; for ( int i= 0 ;i<y;i++){ result*=x; } return result; } public static double factorial( int n) { double result= 1 ; for ( int i= 1 ;i<=n;i++){ result*=i; } return result; } public static double exp( double x) { int n = 0 ; double sum = 0.0 ; double temp = 0.0 ; while ( true ){ temp=us(x,n)/factorial(n); sum+=temp; n++; if (temp< 0.01 ){ break ; } } return sum; } public static double cos( double x) { int n = 0 ; double sum = 0.0 ; double temp = 0.0 ; x=x%( 2.0 *Math.PI); while ( true ) { temp=us(x, 2 *n)/factorial( 2 *n); sum+=temp*(us(- 1.0 ,n)); n++; if (temp< 0.01 ){ break ; } } return sum; } public static double g( double
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: x) { double sum= 0.0 ; for ( int n= ;n<= 100 ;n++){ sum+=cos(Math.PI*x*Math.pow(n, 0.5 )); } return sum; } public static double f( double x) { double sum1= 0.0 ; double sum2= 0.0 ; for ( int n= 1 ;n< 21 ;n++){ sum1+=(n*Math.PI*us(x,( 2 *n+ 1 ))); } for ( int n= 21 ;n<= 40 ;n++){ sum2+=factorial(n-1 )*exp(x); } return sum1+sum2; } public static void main(String[] args) { double result; result=g( 3.27 ) + f( 3.27 ); System.out.println(result); } File: /home/mentalx/Desktop/kmu255_codes/quiz3.java Page 2 of 2 }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

q3 QuÄ±z - x double sum= 0.0 for int n=;n<= 100;n sum...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online