[ create a new paste ] login | about

Link: http://codepad.org/8fUtsZ61    [ raw code | output | fork ]

outoftime - C++, pasted on Feb 12:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

double exp(const int &i, const int &n, unsigned f = 1) {
    return i == 1
        ? 2 + exp(i + 1, n, f)
        : (i < n
            ? 1.0 / (f * i) + exp(i + 1, n, f * i)
            : 0);
}

int main()
{
    printf("E=%.4f", exp(1, 10));
}


Output:
1
E=2.7183


Create a new paste based on this one


Comments: