#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Retorna el valor de la serie de potencias
double getSeriePot(double x, double cen)
{ double termino=1.0,lim=0.000000001,total=0.0,pos=0.0,neg=0.0;
int i=0,k;
while(fabs(termino)>lim)
{ termino=1.0; k=0;
while(k<i)
{ termino=termino*((x+cen)/(k+1));
k++;
}// fin de while
// Hallar el termino
i++;
if(termino>=0.0) pos=pos+termino;
else neg=neg+termino;
//printf("\n %e",total);
}// fin de while
total=pos+neg;
return(total);
}// fin de funcion
// funcion principal
int main(int argc, char *argv[])
{
double x,res;
printf("\n Converge a e^x, suma de serie de potencias");
printf("\n Teclee el valor de X a evaluar: "); scanf("%lf",&x);
if(x>=0) res=getSeriePot(x,0.0);
else res=1.0/getSeriePot(fabs(x),0.0);
printf("\n El valor e^x: %e",res);
return 0;
}
Espero sea de ayuda.
Saludos - FaithHeart
No hay comentarios:
Publicar un comentario