Kodewick
Start learning →
Basic←→0 / 50

Sum of factorials

#011Basicsum += f5 min

Work out 1! + 2! + 3! + … + 20! and show it. For the first 3 terms: 1 + 2 + 6 = 9. No need to multiply from 1 for each term: i! is just (i−1)! times i. In the starter, f holds the factorial of the last term and sum holds the total.

Should show
2561327494111820313
main.c
#include <stdio.h>

int main(void) {
    long long sum = 0, f = 1;
    for (int i = 1; i <= 20; i++) {
        // your code here: turn f into i!, then add it to sum
    }
    printf("%lld\n", sum);
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.