import java.util.*;
public class SumOfHarmonicSeries {
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
System.out.print("Enter number of terms (n):");
int n=scan.nextInt();
double sum=0;
for(int i=1;i<=n;i++)
{
sum=sum + 1.0/i;
}
System.out.println("Sum of Harmonic Series ="+sum);
}
}
Responses
0 Respones to "24. Write a program to determine the sum of the following harmonic series for a given value of n. 1+ ½ + 1/3 + …. + 1/n"
Post a Comment