Program to find the exponential series of 1+x+ x2/2! + x3/3! + ........ + xn/n! in C language



Image result for exponential series expansion

Generally the expansion for the exponential series is like above.
the C program for this is as below.


#include<stdio.h>
#include<math.h>
int fact(int f)
{
if(f>1)
return f*fact(f-1);
return 1;
}
void main()
{
int x,n,i,j;
float sum=1;
printf("Enter the 'x' value:\n");
scanf("%d",&x);
printf("\nEnter the 'n' value:\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+(pow(x,i)/fact(i));
}
printf("\nSum of the series : %f ",sum);
}


Output:

Comments

Popular posts from this blog

Install VS-Code in Manjaro Linux

Running (pre-loaded)Virtual Machine on VirtualBox

Integrating Bash on Windows(Linux subsystem) into VSCode