Friday, March 18, 2016

Write a C Program to find the sum of factorial of 'n' numbers

/*=================================================================================
**
**  File Name     : sumFact.c
**  Creation Date : Sat 19 Mar 2016 03:38:50 AM IST
**  Last Modified : Sat 19 Mar 2016 03:50:55 AM IST
**  Compoler      : gcc
**  Author        : Manoj Kumar Patra, manojpatra.sit@gmail.com
**  Organization  : SCIS, University of Hyderabad, India.
**
**===============================================================================*/

#include<stdio.h>
int main()
{
        printf("\n= = = = = = = C Program to find sum of 'n' factorial = = = = = = =\n");
        int n, i, j, sum=0, fact=1;
        printf("\nEnter the value of 'n' : ");
        scanf("%d",&n);
        for(i=1; i<=n; i++)
        {
                for(j=1; j<=i; j++)
                {
                        fact=fact*j;
                }
                sum=sum+fact;
                fact=1;
        }
        printf("\nThe sum of factorial of 1 to %d is : %d\n",n,sum);
        printf("\n= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n");
}

OutPut:

max@ubuntu:~/cprog$ gcc sumFact.c -o sumFact
max@ubuntu:~/cprog$ ./sumFact

= = = = = = = C Program to find sum of 'n' factorial = = = = = = =

Enter the value of 'n' : 6

The sum of factorial of 1 to 6 is : 873

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
max@ubuntu:~/cprog$ ./sumFact

= = = = = = = C Program to find sum of 'n' factorial = = = = = = =

Enter the value of 'n' : 10

The sum of factorial of 1 to 10 is : 4037913

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

No comments:

Post a Comment