Calculating sum of digits in “100!”

C program for calculating sum of digits in 100!

#include<stdio.h>
#define MAX 10000
void factorialof(int);
void multiply(int);
int length = 0;
int fact[MAX];

int main(){
int num;
int i,k ;
long int r, sum=0;

printf(“Enter number : “);
scanf(“%d”,&num);

fact[0]=1;

factorialof(num);
for(i=length;i>=0;i–)
{
sum=sum+fact[i];
}
printf(“sum of digits is: %d”, sum );
return 0;
}
void factorialof(int num)
{
int i;
for(i=2;i<=num;i++)
{
multiply(i);
}
}
void multiply(int num)
{
long i,r=0;
int arr[MAX];
for(i=0;i<=length;i++)
{
arr[i]=fact[i];
}

for(i=0;i<=length;i++){
fact[i] = (arr[i]*num + r)%10;
r = (arr[i]*num + r)/10;

}
if(r!=0){
while(r!=0){
fact[i]=r%10;
r= r/10;
i++;
}
}
length = i-1;
}

Advertisements

One thought on “Calculating sum of digits in “100!”

  1. Mason says:

    To grow up your business with php developers. we have certified secure server with SSL Secure Server, Security algorithms, Profiles and Valid users. Web Based Support Desk Software and Security is the area in which we have invested more and take it very seriously, which is why we have not conformed to the common safety practices and have gone further, making this issue a priority in the system and achieving Calculating sum of digits in 100! | [/*sumit pathak A.K.A … that is extremely safe. – Mason

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s