Last active
September 21, 2016 21:04
-
-
Save ivanbarlog/3e2066b950e43f9f6569 to your computer and use it in GitHub Desktop.
Power of recursion
This file contains 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 <stdio.h> | |
unsigned int factorial(unsigned int x); | |
int main() { | |
/* testing code */ | |
printf("1! = %i\n", factorial(1)); | |
printf("3! = %i\n", factorial(3)); | |
printf("5! = %i\n", factorial(5)); | |
} | |
unsigned int factorial(unsigned int x) { | |
return (x > 1) ? x * factorial(x - 1) : 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment