Thursday 26 January 2012

Write a C program to calculate the following Sum:- sum=1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10!

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
    int ct, ft;
    float sum=0, x, power, fact;
    clrscr();
    printf("--------PROGRAM FOR SUM OF EQ. SERIES------");
    printf("\n\nEnter the value of X : ");
    scanf( "%f", &x);
    ct=0;
    for(power=0; power<=10; power=power+2)
    {
        fact=1; for(ft=power; ft>=1; ft--)
        fact =fact* ft;
        sum=sum+(pow(-1,ct)*(pow(x,power)/fact)); //EQ. FOR SUM SERIES
        ct++;
    }
    printf("\n Sum : %f",sum);
    getch();
}

2 comments: