WAP to find sum s=1*(1*2)+(1*2*3)+.......+(1*2*3*.........*n);
Answers
Answer:
// 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.sum(n);
return 0;
}
// This code is contributed by SoM15242.
C++ program for finding this....
# Python program to find the sum of series
def sum(n):
i = 1
s = 0.0
for i in range(1, n+1):
s = s + 1/i;
return s;
# Driver Code
n = 5
print("Sum is", round(sum(n), 6))
# This code is contributed by Chinmoy Lenka
python program for finding this......
if want more than ask me here.....