#include<stdio.h>//header file
#include<conio.h>//header file
#include<math.h>//header file
void main() //starting of the main() function
{
int x,n,i,j; //declaration of the variables
long int c=1;
float h,s=0;
clrscr();
printf("program that calculates the sum of the series 1-(x^1)/1!+(x^2)/2!-");
printf("\n\n\n\t\t------------INPUT-------------");
printf("\n\nenter the value of x and the power for range");//taking input from the user
scanf("%d%d",&x,&n);
if(x==0)
{
s=0;
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\n\nthe sum of 1+x+x^2/2!+x^3/3!+______+x^n/n! is=%f",s);//printing output
getch();
exit(0);
}
for(i=1;i<=n;i++)
{
for(j=2;j<=i-1;j++)
c=c*j;
h=pow(x,i-1);
s=s+(pow(-1,i-1))*(h/c);
c=1;
}
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\n\nthe sum of 1+x+x^2/2!+x^3/3!+______+x^n/n! is=%f",s);//printing output
getch();
}