title: Sum Series 23 45 67 89 Upto N Terms
signature: double sumSeries23456789UptoNTerms(int n) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(double actual, double expected){
      return abs(actual - expected) < 1e-09;
  }
  
  string driver(int n, double expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver(49, 0.7803986631477524); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver(4, -0.16507936507936516); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver(60, -0.21050375120783382); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver(90, -0.21185466678122022); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver(96, -0.2120245854859959); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver(29, 0.7770671416747363); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver(86, -0.21172836828074082); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver(47, 0.780190394898247); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver(77, 0.7821931668684383); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver(87, 0.7825573460049735); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def sum_series_23_45_67_89_upto_n_terms(n):
      i = 1
      res = 0.0
      sign = True
      while (n > 0):
          n = (n - 1)
          if sign:
              sign = False
              res = (res + ((i + 1) / (i + 2)))
              i = (i + 2)
          else:
              sign = True
              res = (res - ((i + 1) / (i + 2)))
              i = (i + 2)
      return res
source_cpp: double sum_series_23_45_67_89_upto_n_terms(int n) {
    int i = 1;
    double res = 0.0;
    bool sign = true;
    while ( n > 0 ) {
      n --;
      if ( sign ) {
        sign = ! sign;
        res = res + ( double ) ++ i / ++ i;
      }
      else {
        sign = ! sign;
        res = res - ( double ) ++ i / ++ i;
      }
    }
    return res;
  }