Search C Program | nimishsoft@gmail.com

Series Program 4


1! + 2! + 3! + 4! + 5! + ... + n!

long fact(int n)
{
    long i, f=1;
    for(i=1;i<=n;i++)
    {
        f=f*i;
    }
    return f;
}

int main()
{
    long i,n,sum=0;
    n=5;
    for(i=1;i<=n;i++)
    {
        sum=sum+fact(i);
    }
    printf("Sum: %d",sum);
    return 0;
}


Related Links:
- More Series Programs
- Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C

5 comments:

  1. It is giving me the wrong value

    ReplyDelete
  2. #include
    int main()
    {
    int i,n,sum=0,result=1;
    printf("enter the last number : ");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    result=result*i;
    sum = sum+result;
    }
    printf("resulr= %d\n",sum);
    return 0;
    }

    ReplyDelete