Write a Program in Java to print the following: 1/1 - 2/2! + 3/3! - 4/4! .......n/n!
Answers
Answered by
1
import java.io.*;
import java.lang.*;
public class Demo{
public static double pattern_sum(double val){
double residual = 0, factorial_val = 1;
for (int i = 1; i <= val; i++){
factorial_val = factorial_val * i;
residual = residual + (i / factorial_val);
}
return (residual);
}
public static void main(String[] args){
double val = 6;
System.out.println("The sum of the series is : " + pattern_sum(val));
}
}
PLEASE FOLLOW ME
Similar questions