Series of e in C Program Example

How to write a c program series of e in C programming ?



Solution:
#include <stdio.h>

double e(double x);

int main()
{
double x;

printf("Enter x: ");
scanf("%lf", &x);

printf("e ^ %lf = %lf\n", x, e(x));

return 0;
}

double e(double x)
{
double ans = 0;
double term = 1;
int i;

for(i = 1; i < 10; i++)
{
ans += term;
term *= x/i;
}

return ans;
}


Learn More :