post #1 of 1
Thread Starter 
Can somebody tell me what's wrong in this code? Or can anybody edit it out?
I'm tryin' to have a term to have the sum. But I have this glitch in the program. If I enter 5 for example, the answer output for 5 will be correct but the preceding answers for the numbers before it are wrong. And it should stop when last term is <=.0001.

#include <stdio.h>
#include <math.h>


int exponential (int x);
int factorial (int n);

main ()
{
int x,
choice;
do
{
printf ("Please enter the value of the exponential: ");
scanf ("%d", &x);
exponential (x);
printf("\
Do you want to continue? Press 1 to continue or 0 to quit.");
scanf ("%d",&choice);
}
while(choice==1);
return 0;
}

int exponential (int x)
{
double sum_exp = 1;
int i;
printf ("\
x\\exp(x)\
");
printf ("\
0\\1.0000\
");
for (i=1;i<=x;i++)
{
sum_exp = sum_exp + (pow (x, i)/factorial (i));
printf("\
%d\\%.4lf\
",i, sum_exp);
}
}
int factorial (int n)
{
if (n<=1)
{
return (1);
}
else
{
n = n * factorial (n - 1);
}
return (n);
}