Computer Science, asked by friendsforever7244, 6 months ago

Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n

Please friends it's a humble request
Don't Give irrelevant answers otherwise Your answer will be directly reported
Radhe Radhe ❤️✌️​

Answers

Answered by Oreki
2

import java.util.Scanner;

public class SeriesSum {

public static void main(String[ ] args) {

System.out.print("Enter n - ");

int n = new Scanner(System.in).nextInt( );

float sum = 0;

for (int i = 1; i <= n; i++, sum += 1f / i);

System.out.println("Sum of series - " + sum);

}

}

Answered by Vyomsingh
3

Question:-

Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n

_________________________________

Code:-

class Series

{

void main(int n)

{

double sum=0.0;

for(double k=1;k<=n;k++)

{

sum=sum+(1/k);

}

System.out.println(sum);

}

}

_______________________________

Input:-

2

Output:-

1.5

Similar questions