I'm trying to run a program that does certain operations on factorials of large numbers (say 50!; viz 3.041e+64 - huge!) and therefore doesn't fit in the normal int data types that I'm aware of(unsigned long long int etc)
Which data type do I use to store these values?
P.S I was trying to find the trailing zeroes in a factorial. The following was my approach:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int FactorialFinder(int a)
{
if (a>1)
a= a* (FactorialFinder(a-1)) ;
return a;
}
int main()
{
printf("Enter number \n");
int num ;
scanf("%d",&num) ;
printf("number is %d\n",num);
printf("Factorial is %d",(num = FactorialFinder(num))) ;
int x=0, count = 0 ;
while(num>0)
{
x = (num%10) ;
if (x == 0)
count++ ;
else
break;
num= num/10 ;
}
printf("\nNumber of trailing zeroes is %d",count) ;
getchar() ;
return 0;
}
Works fine upto 12! beyond which the results are erroneous (from 17! it starts returning negative factorial values(?), from 34! it gives 0) I'm guessing due to the datatype problem. Can someone help me out?