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:
Post a Comment