Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- double factorial(int arg)
- {
- if(arg < 2)
- {
- return arg;
- }
- else
- {
- return arg * factorial(arg - 1);
- }
- }
- int main()
- {
- using namespace std;
- int CountOfElements = 10;
- double eps = 0.01;
- double buffForOneElem = 0;
- double accumForAllElems = 0;
- double delta = 1;
- int n = 1;
- int k = 1;
- for(int k = 1; k < CountOfElements; k++)
- {
- buffForOneElem = 0;
- n = 1;
- do
- {
- delta = (pow(n, k) / factorial(n));
- buffForOneElem += delta;
- n++;
- }while(delta > eps);
- buffForOneElem /= M_E;
- cout << k << "th element is " << round(buffForOneElem) << endl;
- accumForAllElems += buffForOneElem;
- }
- cout << "Sum of " << CountOfElements << " elements is " << accumForAllElems << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement