Value of e^x
vofex() returns the value of e^x without using built-in function and it takes 1 parameter as x.
Code
#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "iomanip"
#include "math.h"
using namespace std;
double factorial(long number)
{
double factorial=1;
for(int i=number;i>0;i--)
factorial=factorial*i;
return factorial;
}
double vofex(double x)
{
double sum=1;
for(int i=1;i<11;i++)
sum=sum+(pow(x,i)/factorial(i));
return sum;
}
int main()
{
cout << vofex ( 2.0 ) << endl ;
_getche();
return 0;
}
Output
7.38899
0 comments:
Post a Comment