Program to find Sum of a Series a ^ 1 / 1 ! + a ^ 2 / 2 ! + a ^ 3 / 3 ! + a ^ 4 / 4 ! + Ã ¢ â ‚¬¦ Ã ¢ â ‚¬¦ . + a ^ n / n ! | CPP program to print the sum of series ; function to calculate sum of given series ; multiply ( a / i ) to previous term ; store result in res ; Driver Function
#include <bits/stdc++.h> NEW_LINE using namespace std ; double sumOfSeries ( double a , double num ) { double res = 0 , prev = 1 ; for ( int i = 1 ; i <= num ; i ++ ) { prev *= ( a / i ) ; res = res + prev ; } return ( res ) ; } int main ( ) { double n = 5 , a = 2 ; cout << sumOfSeries ( a , n ) ; return 0 ; }