#include <stdio.h>
int main()
{
int num = 40585;
int output = 0;
for (int x = num; x > 0; x /=10)
{
int temp = 1;
int y = x % 10;
for (int i = y; i > 1; i--)
temp *= i;
output += temp;
}
if (output == num)
printf("True");
else
printf("False");
}
I thought when i became 0, the statement in the inner for loop would not run so output would be 0. When added all, I thought the result was 40584.
When
xis 40,yis set to 0, and no iterations of the loop oniare executed.This leaves
tempunchanged.tempwas initialized to 1, so it remains 1, andoutput += tempadds 1 tooutput.This matches the mathematical definition of the factorial of 0, as 0! = 1.