Ian Dorian Macleod
Problem 20
Problem Statement

n! means n × (n − 1) × ... × 3 × 2 × 1

For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number 100!

url: https://projecteuler.net/problem=20
Approach

C++ implementation

#include <stdc++.h> 
using namespace std;

void multiply(vector& ans, int n) {
    int carry = 0; 
    while(n > 0) {
        if (n % 10 != 0) {
            for(int i = ans.size()-1; i >= 0; i--) {
                int tmp = carry;
                carry = ((ans[i] * (n % 10)) + tmp) / 10;
                ans[i] = ((ans[i] * (n % 10)) + tmp) % 10;
            }
            if (carry != 0) ans.insert(ans.begin(), carry);
        }
        padding++;
        n /= 10;
    }
}

int main() {
    vector ans = {1};
    for(int i = 2; i <= 100; i++) {
        multiply(ans, i);
    }
    for (auto& x : ans) cout << x;
    cout << endl;
    cout << accumulate(ans.begin(), ans.end(), 0) << endl;
    return 0;
}

You can also download the source code for this problem here and compile it on your local machine.
Further Analysis