Adding factorials

Adding factorials. Given an integer n, calculate and print the sum of the factorials from 1! to n!:

1! + 2! + 3! + … + n!

This problem can be solved using only one loop. Do not use the math library.

Test Case Input (n) Expected Output
1 3 9
2 4 33
3 5 153