# Find the Sum of the series 1 + 1/3 + 1/5 + 1/7 + … till N terms

Given a number N, the task is to find the sum of the below series till N terms. Examples:

Input: N = 10
Output: 2.133256
Explanation:
The sum of series 1 + 1/3 + 1/5 + 1/7 + 1/9 + 1/11 is 2.133256.

Input: N = 20
Output: 2.479674
Explanation:
The sum of series 1 + 1/3 + 1/5 + 1/7 + … + 1/41 is 2.479674.

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: From the given series, find the formula for Nth term:

1st term = 1
2nd term = 1/3
3rd term = 1/5
4th term = 1/7
.
.
Nthe term = 1 / (2 * N - 1))


Therefore:

Nth term of the series Then iterate over numbers in the range [1, N] to find all the terms using the above formula and compute their sum.

Below is the implementation of the above approach:

## C++

 // C++ program to find the sum of the  // series 1 + 1/3 + 1/5 + ...     #include  using namespace std;     // Function to find the sum of the  // given series  void printSumSeries(int N)  {      // Intialise the sum to 0      float sum = 0;         for (int i = 1; i <= N; i++) {             // Generate the ith term and          // add it to the sum          sum += 1.0 / (2 * i - 1);      }         // Print the final sum      cout << sum << endl;  }     // Driver Code  int main()  {      int N = 6;         printSumSeries(N);      return 0;  }

## Java

 // Java program to find the sum of the  // series 1 + 1/3 + 1/5 + ...  class GFG {             // Function to find the sum of the      // given series      static void printSumSeries(int N)      {          // Intialise the sum to 0          float sum = 0;                 for (int i = 1; i <= N; i++) {                     // Generate the ith term and              // add it to the sum              sum += 1.0 / (2 * i - 1);          }                 // Print the final sum          System.out.println(sum);      }             // Driver Code      public static void main (String[] args)      {          int N = 6;                 printSumSeries(N);         }         }     // This code is contributed by AnkitRai01

## Python3

 # Python3 program to find the sum of the  # series 1 + 1/3 + 1/5 + ...     # Function to find the sum of the  # given series  def printSumSeries(N) :         # Intialise the sum to 0      sum = 0;         for i in range(1, N + 1) :             # Generate the ith term and          # add it to the sum          sum += 1.0 / (2 * i - 1);         # Print the final sum      print(sum);     # Driver Code  if __name__ == "__main__" :         N = 6;         printSumSeries(N);     # This code is contributed by AnkitRai01

## C#

 // C# program to find the sum of the  // series 1 + 1/3 + 1/5 + ...  using System;     class GFG {             // Function to find the sum of the      // given series      static void printSumSeries(int N)      {          // Intialise the sum to 0          float sum = 0;                 for (int i = 1; i <= N; i++) {                     // Generate the ith term and              // add it to the sum              sum += (float)1.0 / (2 * i - 1);          }                 // Print the final sum          Console.WriteLine(sum);      }             // Driver Code      public static void Main (string[] args)      {          int N = 6;                 printSumSeries(N);      }      }     // This code is contributed by AnkitRai01

Output:

1.87821


Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : AnkitRai01