Edit - Changed title to match the actual problem statement.
I'm programming a function that calculates the sum of digits in 100! but I seem to be having two big issues.
The actual result of 100! is only accurate to the first few numbers (actual result is 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000)
My method for adding up the digits of the resulting number doesn't output the correct result.
This is my current code:
void factorialSum()
{
double fact100 = factorial(100);
double suma = 0;
printf("100! is equal to: %.0f", fact100);
while (fact100 > 0)
{
double temporal = fmod(fact100, 10);
suma = suma + temporal;
fact100 = fact100/10;
}
printf("\nThe sum of all digits in 100! is: %.0f", suma);
}
And the function factorial() is defined as:
double factorial (double n)
{
double mult = 1;
double i = n;
while (i>=1)
{
mult *= i;
i = i - 1;
}
return mult;
}
The program outputs 93326215443944102188325606108575267240944254854960571509166910400407995064242937148632694030450512898042989296944474898258737204311236641477561877016501813248 as a result for 100! and says the summation of its digits is equal to 666.
Any help is appreciated, thank you.