/* Write a C program that computes the value ex by using the formula ex= 1 + x/1! + x2/2! + x3/3! + .... */ #include #include void main() { int n,x,i; float e=0.0; long factorial(int); // Prototype declaration float power(int,int); // Prototype declaration clrscr(); printf("Enter the value of \'n\': "); scanf("%d",&n); printf("Enter the value of \'x\': "); scanf("%d",&x); for(i=0;i<=n;i++) e += power(x,i)/(float)factorial(i); printf("e^x = %-15.7f",e); } // Recursive factorial() function long factorial(int n) { if(n<0) return 0; else if(n==0||n==1) return((long)(1)); else return((long)(n*factorial(n-1))); } // The power() function float power(int a,int b) { int i,flag; float p=1.0; if(b<0) b*=-1,flag=1; else flag=0; for(i=1;i<=b;i++) p *= a; if(flag==0) return p; else return (1/p); }