Get Answers to all your Questions

header-bg qa

wap to find sum of the 1+(1+2)....(1+2+..n) series and print

Answers (1)

best_answer

// Java Program to find the sum of series 
import java.io.*; 

class GFG  
    
    // Function to return sum of 
    // 1/1 + 1/2 + 1/3 + ..+ 1/n 
    static double sum(int n) 
     
    double i, s = 0.0; 
    for (i = 1; i <= n; i++) 
        s = s + 1/i; 
    return s; 
     

    
    // Driven Program 
    public static void main(String args[]) 
     
        int n = 5; 
        System.out.printf("Sum is 0", sum(n)); 
        
     
 
 

Posted by

Deependra Verma

View full answer