Created
December 20, 2017 07:20
-
-
Save camilajenny/102d2d13a1b25cf8b1fce27029b80415 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <functional> | |
using namespace std; | |
int edgeOperation(int &n); | |
int productOperation(int &n); | |
const function<int(int &)> operations[2] = {&productOperation, &edgeOperation}; | |
int edgeOperation(int &n) { | |
--n; | |
return (n + 1) * operations[!!n](n); | |
} | |
int productOperation(int &n) { | |
return 1; | |
} | |
int factorial(int n) { | |
return operations[!!n](n); | |
} | |
int main() { | |
printf("%d\n", factorial(10)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment