Created
November 5, 2018 06:25
-
-
Save meysampg/9a5ccfe6f455a2ed81a23b618944ee1e to your computer and use it in GitHub Desktop.
Recursive factorial without if :-?
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 <iostream> | |
bool fact(int n, int* res) { | |
*res *= n; | |
return n-1 && fact(n-1, res); | |
} | |
int main() { | |
int i; | |
for (int j = 1; i = 1, j < 6; j++) { | |
fact(j, &i); | |
std::cout << "fact(" << j << ") = " << i << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
😄