Sunday, 31 August 2014

Factorial Digit Sum Problem 20 Project euler

main()
{
int x,k;
int sum=0;
int a[3000];
int i;
for(i=0;i<3000;i++)
{a[i]=0;
}
a[2999]=1;
int n;
for(n=100;n>=1;n--)
{
for(i=0;i<3000;i++)
{
x=(a[i])*n;
a[i]=x%10;
x/=10;
k=i-1;
while(x!=0)
{
a[k]+=(x%10);
x/=10;
k--;
}
}
}
for(i=0;i<3000;i++)
{
sum+=a[i];
}
printf("%d",sum);



}










No comments:

Post a Comment