Given two numbers **x** and **N**, the task is to find the value of** cosh(x)** from the series upto **N** terms.

The expansion of cosh(x) is given below:

cosh(x) = 1 + x^{2}/2! + x^{4}/4! + …………

**Examples:**

Input:x = 1, N = 5Output:1.54308035714Input:x = 1, N = 10Output:1.54308063497

**Approach:**

The above series can be easily implemented using a factorial function and loops.

The nth term of the series is:

Below is the implementation of the above approach:

## C++

`// C++ program for ` `// the sum of cosh(x) series ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// function to return the factorial of a number ` `int` `fact(` `int` `n) ` `{ ` ` ` ` ` `int` `i = 1, fac = 1; ` ` ` `for` `(i = 1; i <= n; i++) ` ` ` `fac = fac * i; ` ` ` ` ` `return` `fac; ` `} ` ` ` `// function to return the sum of the series ` `double` `log_Expansion(` `double` `x, ` `int` `n) ` `{ ` ` ` ` ` `double` `sum = 0; ` ` ` `int` `i = 0; ` ` ` ` ` `for` `(i = 0; i < n; i++) { ` ` ` ` ` `sum = sum ` ` ` `+ ` `pow` `(x, 2 * i) ` ` ` `/ fact(2 * i); ` ` ` `} ` ` ` ` ` `return` `sum; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `double` `x = 1; ` ` ` `int` `n = 10; ` ` ` `cout << setprecision(12) ` ` ` `<< log_Expansion(x, n) ` ` ` `<< endl; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program for the sum of ` `// cosh(x) series ` `import` `java.util.*; ` ` ` `class` `GFG ` `{ ` ` ` `// function to return the factorial of a number ` `static` `int` `fact(` `int` `n) ` `{ ` ` ` `int` `i = ` `1` `, fac = ` `1` `; ` ` ` `for` `(i = ` `1` `; i <= n; i++) ` ` ` `fac = fac * i; ` ` ` ` ` `return` `fac; ` `} ` ` ` `// function to return the sum of the series ` `static` `double` `log_Expansion(` `double` `x, ` `int` `n) ` `{ ` ` ` `double` `sum = ` `0` `; ` ` ` `int` `i = ` `0` `; ` ` ` ` ` `for` `(i = ` `0` `; i < n; i++) ` ` ` `{ ` ` ` `sum = sum + Math.pow(x, ` `2` `* i) / ` ` ` `fact(` `2` `* i); ` ` ` `} ` ` ` ` ` `return` `sum; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `double` `x = ` `1` `; ` ` ` `int` `n = ` `10` `; ` ` ` `System.out.println(log_Expansion(x, n)); ` `} ` `} ` ` ` `// This code is contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program for the Sum of cosh(x) series ` ` ` `# function to return the factorial of a number ` `def` `fact(n): ` ` ` ` ` `i, fac ` `=` `1` `, ` `1` ` ` `for` `i ` `in` `range` `(` `1` `, n ` `+` `1` `): ` ` ` `fac ` `=` `fac ` `*` `i ` ` ` ` ` `return` `fac ` ` ` `# function to return the Sum of the series ` `def` `log_Expansion(x, n): ` ` ` ` ` `Sum` `=` `0` ` ` `i ` `=` `0` ` ` ` ` `for` `i ` `in` `range` `(n): ` ` ` ` ` `Sum` `=` `Sum` `+` `pow` `(x, ` `2` `*` `i) ` `/` `fact(` `2` `*` `i) ` ` ` ` ` `return` `Sum` ` ` `# Driver code ` `x ` `=` `1` `n ` `=` `10` `print` `(log_Expansion(x, n)) ` ` ` `# This code is contributed by Mohit Kumar ` |

*chevron_right*

*filter_none*

## C#

`// C# program for the sum of ` `// cosh(x) series ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// function to return the ` `// factorial of a number ` `static` `int` `fact(` `int` `n) ` `{ ` ` ` `int` `i = 1, fac = 1; ` ` ` `for` `(i = 1; i <= n; i++) ` ` ` `fac = fac * i; ` ` ` ` ` `return` `fac; ` `} ` ` ` `// function to return the sum of the series ` `static` `double` `log_Expansion(` `double` `x, ` `int` `n) ` `{ ` ` ` `double` `sum = 0; ` ` ` `int` `i = 0; ` ` ` ` ` `for` `(i = 0; i < n; i++) ` ` ` `{ ` ` ` `sum = sum + Math.Pow(x, 2 * i) / ` ` ` `fact(2 * i); ` ` ` `} ` ` ` ` ` `return` `sum; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `double` `x = 1; ` ` ` `int` `n = 10; ` ` ` `Console.WriteLine(log_Expansion(x, n)); ` `} ` `} ` ` ` `// This code is contributed by PrinciRaj1992 ` |

*chevron_right*

*filter_none*

**Output:**

1.54308063497

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Nth term where K+1th term is product of Kth term with difference of max and min digit of Kth term
- Program to get the Sum of series: 1 - x^2/2! + x^4/4! -.... upto nth term
- Find the Nth term of the series where each term f[i] = f[i - 1] - f[i - 2]
- Find Nth term of the series where each term differs by 6 and 2 alternately
- Program to print tetrahedral numbers upto Nth term
- Program to print pentatope numbers upto Nth term
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- Nth term of given recurrence relation having each term equal to the product of previous K terms
- Sum of series till N-th term whose i-th term is i^k - (i-1)^k
- Program to find the Nth term of the series 3, 7, 13, 21, 31.....
- Program to find the Nth term of series -1, 2, 11, 26, 47......
- Program to find Nth term of series 9, 23, 45, 75, 113...
- Program to find Nth term in the series 0, 2, 1, 3, 1, 5, 2, 7, 3,…
- Program to find the Nth term of the series 3, 20, 63, 144, 230, ……
- Program to find the Nth term of series 5, 10, 17, 26, 37, 50, 65, 82, ...
- Program to find the Nth term of series 0, 4, 14, 30, 51, 80, 114, 154, 200, ...
- Program to find the Nth term of the series 0, 14, 40, 78, 124, ...
- Program to find the Nth term of the series 0, 5, 14, 27, 44, ........
- Program to find Nth term of the series 3, 6, 18, 24, ...
- Program to find Nth term of the series 2, 4, 3, 4, 15...

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.