Write a program to find the series:
1+1/3+1/5+.................................+1/20
Answers
Answered by
4
import java.util.*;
public class Series
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int a=0,i;
for(i=1;i<=20;i=i+2)
{
a=a/i;
System.out.println("Display the series"+a);
}
}
}
Answered by
8
// 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.
Similar questions
Math,
6 months ago
India Languages,
6 months ago
Chemistry,
1 year ago
Computer Science,
1 year ago
English,
1 year ago