RECURSIVE EXPONENTIAL FUNCTION


This program illustrates the use of recursion to compute any power series.


#include"stdio.h"
#include"math.h"
float e(float,int);
main()
{
float x,p;
int n;
clrscr();
printf("enter n,x:");
scanf("%d %f",&n,&x);
p=e(x,n);
printf("%g",e(x,n));
getch();
}

float e(float x,int n)
{
if(n==0)
return 1;
else
return e(x,n-1)+pow(x,n)/fact(n);
}

fact(int n)
{
int a;
a=1;
while(n>1)
{
a=a*n;
n--;
}
return a;
}

Go to the programs page click here!!

Hosted by www.Geocities.ws

1