+92 332 4229 857 99ProjectIdeas@Gmail.com

How to calculate the value of e using series (C++)


Value of e
vofe() returns the value of e without using built-in function.

Code

#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "iomanip"

using namespace std;

double factorial(long number)
{
double factorial=1;

 for(int i=number;i>0;i--)
  factorial=factorial*i;

return factorial;
}

double vofe()
{
       double sum=1;
   
              for(int i=1;i<9;i++)
            sum=sum+(1/factorial(i));
return sum;
}

int main()
{
       cout << vofe() << endl ;

       _getche();
       return 0;
}

Output
2.71828

0 comments: