124. C Program to Compute the 1+x+x2/2!+x3/3!+x4/4!+ ………. xn/n! exponential series.
How does this program work?
- This program is used to compute the sum of series for the given exponential order.
- Here we are going to find the series for 1+x+x2/2!+x3/3!+x4/4!+ ………. xn/n! upto nth term.
- where The nth term is the user input.
- Computing the given series is easy by Using the simple for loop condition and by using the exponential formula.
Here is the code
#include <stdio.h>
int main(void)
{
int i, n;
float x, sum=1, t=1;
printf("Enter the value for x : \n");
scanf("%f", &x);
printf("\nEnter the value for n : \n");
scanf("%d", &n);
/* Loop to calculate the value of Exponential */
for(i=1;i<=n;i++)
{
t=t*x/i;
sum=sum+t;
}
printf("\nThe Exponential Value of %f = %.4f", x, sum);
return 0;
}