Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   source code for c++ program for exponential function (http://www.go4expert.com/forums/source-code-cpp-program-exponential-t26671/)

moniratna 12Sep2011 18:31

source code for c++ program for exponential function
 
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...


poornaMoksha 13Sep2011 07:03

Re: source code for c++ program for exponential function
 
Have you compiled this?
Whats the problem you are facing?


All times are GMT +5.5. The time now is 22:04.