wap in Java to find sum of
1+1/(1+2)+1/(1+2+3)+1/(1+2+3+........n)
Answers
Explanation:
If inverse of a sequence follows rule of an A.P i.e, Arithmetic progression, then it is said to be in Harmonic Progression.In general, the terms in a harmonic progression can be denoted as : 1/a, 1/(a + d), 1/(a + 2d), 1/(a + 3d) …. 1/(a + nd).
As Nth term of AP is given as ( a + (n – 1)d) .Hence, Nth term of harmonic progression is reciprocal of Nth term of AP, which is : 1/(a + (n – 1)d)
where “a” is the 1st term of AP and “d” is the common difference.
We can use a for loop to find sum.
// C++ program to find sum of series
#include <iostream>
using namespace std;
// Function to return sum of
// 1/1 + 1/2 + 1/3 + ..+ 1/n
class gfg
{
public : double sum(int n)
{
double i, s = 0.0;
for (i = 1; i <= n; i++)
s = s + 1/i;
return s;
}
};
// Driver code
int main()
{
gfg g;
int n = 5;
cout << "Sum is " << g.
Hope it helps
Plz Mark brainlist