title: Sum Series 23 45 67 89 Upto N Terms
signature: class Solution {
  
      public decimal SumSeries23456789UptoNTerms(int n) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(decimal actual, decimal expected){
              return Math.Abs(actual - expected) < 1e-09m;
          }
  
          public string driver(int n, decimal expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                decimal pred_result = solution_cls.PLACEHOLDER_FN_NAME(n); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  49, 
                  0.7803986631477524m
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  4, 
                  -0.16507936507936516m
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  60, 
                  -0.21050375120783382m
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  90, 
                  -0.21185466678122022m
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  96, 
                  -0.2120245854859959m
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  29, 
                  0.7770671416747363m
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  86, 
                  -0.21172836828074082m
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  47, 
                  0.780190394898247m
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  77, 
                  0.7821931668684383m
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  87, 
                  0.7825573460049735m
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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;
  }