-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
51 lines (44 loc) · 1020 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
long double Nfactorial(long double y)
{
long double factorial = 1.0;
if(y == 0.0)
return factorial;
else
{
for(long double i = y; i > 0.0; --i)
{
factorial = factorial * i;
}
return factorial;
}
}
long double M(long double x)
{
long double partial_sum = 0.0;
for(long double i = 0.0; i < x; ++i)
{
long double x_over_n = (1.0 / Nfactorial(i));
partial_sum = partial_sum + x_over_n;
}
return partial_sum;
}
int main()
{
long double n = 23.0;
long double nth_e = M(n);
ofstream obj("e_expansion.txt",::ios::app);
if(!obj)
cout<<"Could not open file for output"<<endl;
else
obj<< setprecision(1000) << nth_e <<endl;
cout<< "The Maclauren expansion of e^1 to n = " << n <<": "<<endl;
cout<<"\n"<< setprecision(48) << nth_e ;
cin.sync();
cin.get();
return 0;
}