Sum of Harmonic Progression
This program calculates sum of harmonic progression series.
Problem Statement
Write a Java program that calculates sum of harmonic progression up to 1/6 using for loop.
Source Code
| 1 | public class SumHarmonicProgression { |
| 2 | public static void main(String[] args) { |
| 3 | int n = 6; |
| 4 | double sum = 0.0; |
| 5 | for(int i=1; i<=n; i++) { |
| 6 | sum += 1.0/i; |
| 7 | } |
| 8 | System.out.println("Sum of harmonic progression = " + sum + " - Eduinq"); |
| 9 | } |
| 10 | } |
Program Output
Sum of harmonic progression = 2.45 - Eduinq
Explanation
The program adds reciprocals of integers from 1 to 6. This demonstrates harmonic progression summation using for loop. Shows how for loop can calculate harmonic progression sums.