title: Sum Series 23 45 67 89 Upto N Terms
signature: func sumSeries23456789UptoNTerms(n int) float64 {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual float64, expected float64) bool {
      return math.Abs(actual - expected) < 1e-09
  }
  
  func driver(n int, expected float64) string {
      if validateSolution(PLACEHOLDER_FN_NAME(n),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver(49, 0.7803986631477524)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(4, -0.16507936507936516)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(60, -0.21050375120783382)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(90, -0.21185466678122022)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(96, -0.2120245854859959)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(29, 0.7770671416747363)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(86, -0.21172836828074082)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(47, 0.780190394898247)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(77, 0.7821931668684383)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(87, 0.7825573460049735)
      fmt.Printf("TEST-9...%s\n", 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;
  }