C Program to print the series sum : (1 / 1!) - (2 / 3!) + (3 / 5!)......upto n terms


 

// Program by Akash Tripathi (@proakash256) 
#include <stdio.h>
unsigned long long factorial(int n)
{
    unsigned long long f = 1;;
    for(int i = ni >= 2i = i - 1)
        f = f * i;
    return f;
}
int main()
{
    int n;
    float s = 0;
    printf("Enter the number of terms upto which you want 
to print the series : ");
    scanf("%d" , &n);
    for(int i = 1 , b = 1i <= ni = i + 1 , b = b + 2)
    {
        unsigned long long f = factorial(b);
        if(i % 2 == 0)
            s = s - ((float)i / f);
        else
            s = s + (i / (float)f);
    }
    printf("\nThe Sum of the series upto %d terms is %0.2f" , n , s);
    return 0;
}

Comments