I am learning C and I was asked to compute e^x and compare it with the value given by exp function in math.h and this is what I did:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
double exponential( double x , double n, double p ){
double i=1;
if(n<0)
return i;
else
i=i+(x/p)*(exponential(x,n-0.00001,p+1));}
int main(){
double x,n,p;
scanf("%lf",&x);
printf("math.h e^x = %lf\n",exp(x));
printf("calculated e^x = %lf\n",exponential(x,1,1));
return 0;}
but I was only getting correct answers up to x = 30 after that its deviating more as I increase x. Can someone tell me how I should change the code for more precision.