
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ program to get the Sum of series: 1 – x^2/2! + x^4/4! -…. upto nth term
In this tutorial, we will be discussing a program to get the sum of series 1 – x^2/2! + x^4/4! … upto nth term.
For this we will be given with the values of x and n. Our task will be to calculate the sum of the given series upto the given n terms. This can be easily done by computing the factorial and using the standard power function to calculate powers.
Example
#include <math.h> #include <stdio.h> //calculating the sum of series double calc_sum(double x, int n){ double sum = 1, term = 1, fct, j, y = 2, m; int i; for (i = 1; i < n; i++) { fct = 1; for (j = 1; j <= y; j++) { fct = fct * j; } term = term * (-1); m = term * pow(x, y) / fct; sum = sum + m; y += 2; } return sum; } int main(){ double x = 5; int n = 7; printf("%.4f", calc_sum(x, n)); return 0; }
Output
0.3469
- Related Articles
- Simplify each of the following products:\( (2 x^{4}-4 x^{2}+1)(2 x^{4}-4 x^{2}-1) \)
- C++ program to find nth Term of the Series 1 2 2 4 4 4 4 8 8 8 8 8 8 8 8 …
- Solve for x:$\frac{1}{x+1} +\frac{2}{x+2} =\frac{4}{x+4} ;\ x\neq -1,\ -2,\ -4$
- Find Sum of Series 1^2 - 2^2 + 3^2 - 4^2 ... upto n terms in C++
- $x+\frac{1}{x}=4$ find the value of the following:a) $x^{2}+\frac{1}{x^{2}}$b) $x^{4}+\frac{1}{x 4}$
- Find the nth term of the given series 0, 0, 2, 1, 4, 2, 6, 3, 8, 4… in C++
- C++ program to find Nth term of the series 0, 2, 4, 8, 12, 18…
- Find x: \( 4^{x-2}+2 \times 2^{2 x-1}=1 \frac{1}{16} \)
- C++ program to find the sum of the series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- If \( x+\frac{1}{x}=11 \), find the value of(a) \( x^{2}+\frac{1}{x^{2}} \)(b) \( x^{4}+\frac{1}{x^{4}} \)
- If \( x-\frac{1}{x}=5 \), find the value of(a) \( x^{2}+\frac{1}{x^{2}} \)(b) \( x^{4}+\frac{1}{x^{4}} \)
- If \( x+\frac{1}{x}=\sqrt{5} \), find the values of \( x^{2}+ \frac{1}{x^{2}} \) and \( x^{4}+\frac{1}{x^{4}} \).
- 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 a 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!

Advertisements