i have the following simple program to calculate factorials.
Code:
#include <stdio.h>
#include <stdlib.h>
double Factorial( int );
double Fact( int );
int main()
{
int x = 24;
double AnswerOne = Factorial( x );
double AnswerTwo = Fact( x );
printf("%lf\n", AnswerOne);
printf("%lf\n", AnswerTwo);
return 0;
}
double Factorial( int number )
{
if ( number == 1 )
return 1;
return number * Factorial( number - 1 );
}
double Fact( int Num )
{
double Answer = 1;
while (Num != 0)
Answer *= Num--;
return Answer;
}
Up to 24! the answers agree but after that they differ Is it the way floating points are stored that causes the error?