Coding Challenges <C++>

What will this program output?

c++
#include <iostream>

unsigned long long factorial(int n) {
    if (n == 0 || n == 1) {
        return 1;
    }
    return n * factorial(n - 1);
}

int sumOfDigits(unsigned long long n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main() {
    unsigned long long fact = factorial(10);
    std::cout << sumOfDigits(fact) << std::endl;
    return 0;
}
Solution
Was this page helpful?