Question #41309
computes the sum of the following series.
Sum=1!+2!+3!+4!+........n!
1
Expert's answer
2014-05-14T11:35:55-0400
#include <iostream>long factorial(long n) {    if ( n < 0 ) {        return -1;    }    if ( n < 2 ) {        return 1;    } else {        return n * factorial(n-1);    }}int main() {    int fact;    long long unsigned sum = 0;    std::cout << "Please enter N " << std::endl;    std::cin >> fact;    for ( long i = 1; i <= fact; i++) {        sum += factorial(i);    }    std::cout << "The sum is " << sum << std::endl;    return 0;}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS