source code for c++ program for exponential function

moniratna's Avatar, Join Date: Sep 2011
Newbie Member
Code:
/*To write a program for exponential function(e^x) upto nth term inputing the values of 'n' & 'x'*/
/*e^x=1+x+x^2/2!+...+x^n/n!*/

#include<iostream.h>

#include<conio.h>

  float factorial(int n)
    { 
      float f=1;
      for(int i=1;i<=n;i++)
        f=f*i;
       return f;
    }

  float series(int n,int x)
    {
      float h=1;
      for(int i=1;i<=n;i++)
       h=h*x;
      return h;
    }

  int main()
    {
     clrscr();
     int n,x,i;
     float s=1;
     cout<<"Enter the value for 'n' & 'x': ";
     cin>>n>>x;
     for(i=1;i<=n;i++)
       s=s+series(i,x)/factorial(i);
     cout<<"The sum= "<<s;
     getch();
     return 0;
    }

//this is my first post... please respond...

Last edited by shabbir; 13Sep2011 at 07:32.. Reason: Code blocks
poornaMoksha's Avatar, Join Date: Jan 2011
Ambitious contributor
Have you compiled this?
Whats the problem you are facing?