# Sum of series 2/3 – 4/5 + 6/7 – 8/9 + ——- upto n terms

Given the value of n, find the sum of the series (2 / 3) – (4 / 5) + (6 / 7) – (8 / 9) + – – – – – – – upto n terms.

Examples :

```Input : n = 5
Output : 0.744012
Series : (2 / 3) - (4 / 5) + (6 / 7) - (8 / 9) + (10 / 11)

Input : n = 7
Output : 0.754268
Series : (2 / 3) - (4 / 5) + (6 / 7) - (8 / 9) +
(10 / 11) - (12 / 13) + (14 / 15)
```

## C++

 `// C++ program to find  ` `// sum of given series ` `#include ` `using` `namespace` `std; ` ` `  `// Function to find sum of series ` `// up-to n terms ` `double` `seriesSum(``int` `n) ` `{ ` `    ``// initializing counter by 1 ` `    ``int` `i = 1; ` `     `  `    ``// variable to calculate result ` `    ``double` `res = 0.0; ` `    ``bool` `sign = ``true``; ` `     `  `    ``// while loop until nth term  ` `    ``// is not reached ` `    ``while` `(n > 0)  ` `    ``{ ` `        ``n--; ` `         `  `        ``// boolean type variable  ` `        ``// for checking validation ` `        ``if` `(sign) { ` `            ``sign = !sign; ` `            ``res = res + (``double``)++i / ++i; ` `        ``} ` `        ``else` `{ ` `            ``sign = !sign; ` `            ``res = res - (``double``)++i / ++i; ` `        ``} ` `    ``} ` `     `  `    ``return` `res; ` `} ` ` `  `// Driver Code ` `int` `main() ` `{ ` `    ``int` `n = 5; ` `    ``cout << seriesSum(n);     ` `    ``return` `0; ` `} `

## Java

 `// Java program to find  ` `// sum of given series ` `import` `java.io.*; ` ` `  `class` `GFG { ` `     `  `    ``// Function to find sum of series ` `    ``// up-to n terms ` `    ``static` `double` `seriesSum(``int` `n) ` `    ``{ ` `     `  `    ``// initializing counter by 1 ` `    ``int` `i = ``1``; ` `     `  `    ``// variable to calculate result ` `    ``double` `res = ``0.0``; ` `    ``boolean` `sign = ``true``; ` `     `  `    ``// while loop until nth term  ` `    ``// is not reached ` `    ``while` `(n > ``0``)  ` `    ``{ ` `        ``n--; ` `         `  `        ``// boolean type variable  ` `        ``// for checking validation ` `        ``if` `(sign) ` `        ``{ ` `            ``sign = !sign; ` `            ``res = res + (``double``)++i / ++i; ` `        ``} ` `         `  `        ``else`  `        ``{ ` `            ``sign = !sign; ` `            ``res = res - (``double``)++i / ++i; ` `        ``} ` `    ``} ` `     `  `    ``return` `res; ` `} ` `     `  `    ``// Driver Code ` `    ``public` `static` `void` `main (String[] args) { ` `         `  `        ``int` `n = ``5``; ` `         `  `        ``System.out.print(seriesSum(n)); ` `    ``} ` `} ` ` `  `// This code is contributed by vt_m `

## Python3

 `# Python3 program to find  ` `# sum of given series ` ` `  `# Function to find ` `# sum of series ` `# up-to n terms ` `def` `seriesSum(n): ` `     `  `    ``# initializing  ` `    ``# counter by 1 ` `    ``i ``=` `1``; ` `     `  `    ``# variable to  ` `    ``# calculate result ` `    ``res ``=` `0.0``; ` `    ``sign ``=` `True``; ` `     `  `    ``# while loop until nth  ` `    ``# term is not reached ` `    ``while` `(n > ``0``):  ` `        ``n ``=` `n ``-` `1``; ` `         `  `        ``# boolean type variable  ` `        ``# for checking validation ` `        ``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; ` ` `  `# Driver Code ` `n ``=` `5``; ` `print``(``round``(seriesSum(n), ``6``));  ` ` `  `# This code is contributed  ` `# by mits `

## C#

 `// C# program to find  ` `// sum of given series ` `using` `System; ` ` `  `class` `GFG { ` `     `  `    ``// Function to find sum of  ` `    ``// series up-to n terms ` `    ``static` `double` `seriesSum(``int` `n) ` `    ``{ ` `     `  `    ``// initializing counter by 1 ` `    ``int` `i = 1; ` `     `  `    ``// variable to calculate result ` `    ``double` `res = 0.0; ` `    ``bool` `sign = ``true``; ` `     `  `    ``// while loop until nth term  ` `    ``// is not reached ` `    ``while` `(n > 0)  ` `    ``{ ` `        ``n--; ` `         `  `        ``// boolean type variable  ` `        ``// for checking validation ` `        ``if` `(sign) ` `        ``{ ` `            ``sign = !sign; ` `            ``res = res + (``double``)++i / ++i; ` `        ``} ` `         `  `        ``else` `        ``{ ` `            ``sign = !sign; ` `            ``res = res - (``double``)++i / ++i; ` `        ``} ` `    ``} ` `     `  `    ``return` `res; ` `} ` `     `  `    ``// Driver Code ` `    ``public` `static` `void` `Main () { ` `         `  `        ``int` `n = 5; ` `        ``Console.Write(seriesSum(n)); ` `    ``} ` `} ` ` `  `// This code is contributed by vt_m `

## PHP

 ` 0)  ` `    ``{ ` `        ``\$n``--; ` `         `  `        ``// boolean type variable  ` `        ``// for checking validation ` `        ``if` `(``\$sign``) { ` `            ``\$sign` `= !``\$sign``; ` `            ``\$res` `= ``\$res` `+ (double)++``\$i` `/ ++``\$i``; ` `        ``} ` `        ``else` `{ ` `            ``\$sign` `= !``\$sign``; ` `            ``\$res` `= ``\$res` `- (double)++``\$i` `/ ++``\$i``; ` `        ``} ` `    ``} ` `     `  `    ``return` `\$res``; ` `} ` ` `  `// Driver Code ` `\$n` `= 5; ` `echo``(seriesSum(``\$n``));  ` ` `  `// This code is contributed by Ajit. ` `?> `

Output :

```0.744012
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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 : jit_t, Mithun Kumar
{"ft_lang_label":"__label__en","ft_lang_prob":0.55298805,"math_prob":0.95602554,"size":5062,"snap":"2020-10-2020-16","text_gpt3_token_len":1759,"char_repetition_ratio":0.1348359,"word_repetition_ratio":0.40677965,"special_character_ratio":0.41268274,"punctuation_ratio":0.18075801,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9996804,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-02-27T02:44:13Z\",\"WARC-Record-ID\":\"<urn:uuid:b745cb78-f88c-48c3-a6cc-df62f10f842f>\",\"Content-Length\":\"173505\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a19d39f9-8041-4755-9cd8-579938e3f89a>\",\"WARC-Concurrent-To\":\"<urn:uuid:3715a8e5-825a-4060-a589-fe102ac00f9b>\",\"WARC-IP-Address\":\"23.45.181.178\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/sum-series-23-45-67-89-upto-n-terms/\",\"WARC-Payload-Digest\":\"sha1:FAVSURYMJPYRYSO26FYWVK2WDAIEPY73\",\"WARC-Block-Digest\":\"sha1:72TFCZFW4SIO3GC2VYBAUE5SA6UEWWUP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-10/CC-MAIN-2020-10_segments_1581875146643.49_warc_CC-MAIN-20200227002351-20200227032351-00549.warc.gz\"}"}