Programming for Problem Solving

GTU Practical 28

28. Write a program to evaluate the series sum=1-x+x^2/2!-x^3/3!+x^4/4!……-x^9/9!
#include<stdio.h>  ( this applies in the given code )

#include
#include
int main()
{
int n,i,j,x,fact=1;
float sum=0;
printf(“\\n Enter Highest Power Value (Max 9):”);
scanf(“%d”,&n);
printf(“\\n Enter the Value of X :”);
scanf(“%d”,&x);
for(i=0;i0;j–)
{
fact=fact*j;
}
if(i%2==0)
{
sum=sum+(pow(x,i)/fact);
}
else
{
sum=sum-(pow(x,i)/fact);
}
}
printf(“\\n Sum of Series = %f”,sum);
return 0;
}

/*
OUTPUT:

Enter Highest Power Value (Max 9):3

Enter the Value of X :2

Sum of Series = -0.333333

*/

OUTPUT

\n Enter Highest Power Value (Max 9):5
\n Enter the Value of X :6
\n Sum of Series = -33.799999

GTU STUDY