recent

a c program to print series

write a c program to print series
1!/1) + (2!/2) + (3!/3) + (4!/4) + (5!/5) + ... + (n!/n)


#include<stdio.h>
long fact(int n)
{
    long j, fact=1;
    for(j=1;j<=n;j++)
    {
        fact=fact*j;
    }
    return fact;
}

int main()
{
    long j,n;
    double sum=0;
    n=5;
    for(j=1;j<=n;j++)
    {
        sum=sum+(fact(j)/j);
    }
    printf("Sum is: %lf",sum);
}
Powered by Blogger.