Tuesday, January 6, 2009

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

#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(math.h)
int main(void)
{
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();
return 0;
}

Explanation:-
Here 'ct' means count .
And variable 'ft' & 'fact' are used to find factorial based 'power' value.

No comments:

Post a Comment