
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sum of series 2/3 – 4/5 + 6/7 – 8/9 + …… upto n terms
A series is a sequence of numbers that have some common traits that each number follows. There are various series defined in mathematics with sum mathematical logic or mathematical formula. In this problem we are given a series of numbers 2/3 , -4/5 , 6/7 , -8/9 , …..
The general term of the series can be defined as (-1)n *(2*n)/ ((2*n)+1)
To find the sum of series, we need to add each element of the given series as, 2/3 - 4/5 + 6/7 - 8/9 + ……
Let's take an example,
Input: 10 Output: -0.191921
Explanation
(2 / 3) - (4 / 5) + (6 / 7) - (8 / 9) + (10 / 11) - (12 / 13) + (14 / 15) - (16 / 17) + (18 / 19) - (20 / 21) = -0.191921
Input: 17 Output: 0.77152
Explanation
(2 / 3) - (4 / 5) + (6 / 7) - (8 / 9) + (10 / 11) - (12 / 13) + (14 / 15) - (16 / 17) + (18 / 19) - (20 / 21) = 0.77152
Example
#include <iostream> using namespace std; int main() { int n = 17,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; } } cout << "The sum of the given series is "<< res; return 0; }
Output
The sum of given series is 0.77152
- Related Questions & Answers
- C++ program to find the sum of the series (1*1) + (2*2) + (3*3) + (4*4) + (5*5) + … + (n*n)
- C++ Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! + …… n/n!
- Python Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- C++ program to find the sum of the series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- Java Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- Sum of the series 1 / 1 + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + … + upto n terms in C++
- Find sum of the series 1-2+3-4+5-6+7....in C++
- Find Sum of Series 1^2 - 2^2 + 3^2 - 4^2 ... upto n terms in C++
- C++ program to get the Sum of series: 1 – x^2/2! + x^4/4! -…. upto nth term
- Program to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8…in C++
- Sum of the series 2 + (2+4) + (2+4+6) + (2+4+6+8) + ... + (2+4+6+8+...+2n) in C++
- Sum of series 1^2 + 3^2 + 5^2 + . . . + (2*n – 1)^2
- Sum of the series 0.7, 0.77, 0.777 … upto n terms in C++
- Program to find Sum of a Series a^1/1! + a^2/2! + a^3/3! + a^4/4! +…….+ a^n/n! in C++
- Find the nth term of the given series 0, 0, 2, 1, 4, 2, 6, 3, 8, 4… in C++
Advertisements