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