Get Answers to all your Questions

header-bg qa

How to make a program of series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n! using java programming language

Answers (1)

best_answer

// Java program to print the sum of series 

import java.io.*; 
import java.lang.*; 

class GFG  
    public static double sumOfSeries(double num) 
     
        double res = 0, fact = 1; 
        for (int i = 1; i <= num; i++)  
            /*fact variable store factorial of the i.*/
            fact = fact * i; 

            res = res + (i / fact); 
         
        return (res); 
     

    public static void main(String[] args) 
     
        double n = 5; 
        System.out.println("Sum: " + sumOfSeries(n)); 
     
 
 

Posted by

Deependra Verma

View full answer