source code for c++ program for exponential function

Discussion in 'C++' started by moniratna, Sep 12, 2011.

  1. moniratna

    moniratna New Member

    Joined:
    Sep 12, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Sep 13, 2011
  2. poornaMoksha

    poornaMoksha New Member

    Joined:
    Jan 29, 2011
    Messages:
    150
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Software developer
    Location:
    India
    Have you compiled this?
    Whats the problem you are facing?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice