Harmonic Progression Java

PROGRAM TO PRINT SUM OF HARMONIC SERIES


import java.io.*; 
class MAIN 
  
    float sum(float n) 
    
        // Base condition 
        if (n < 2
            return 1
  
        else
            return 1 / n + (sum(n - 1)); 
    
  
    // Driven Code 
    public static void main(String args[]) 
    
      GFG g = new GFG(); 
      System.out.println(g.sum(8)); 
      System.out.print(g.sum(10)); 
    
}

OUTPUT
2.7178571428571425
2.9289682539682538

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java