Implements neper number (e) with a recursion function
问题 I want to calculate Neper number( e ) with a recursion function. I have the formula to calculate it: e = (1/0!) + (1/1!) + (1/2!) + (1/3!) +. . . I have the code but it won't work properly: #include <iostream> using namespace std; double f(double res,int i, int n){ return (i == n) ? res: res = res + (1 /f(res,i+1,n)*i); } int main(){ cout << f(1,1,2) << endl; } The result of this code is 2.5 but it should be 2 . Where is the problem? 回答1: Still not sure what you want res for. In fact, if I