# Answer to Question #41309 in Java | JSP | JSF for solomon

Question #41309

computes the sum of the following series.

Sum=1!+2!+3!+4!+........n!

Sum=1!+2!+3!+4!+........n!

Expert's answer

`#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 orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment