Skip to content

Instantly share code, notes, and snippets.

@ivanbarlog
Last active September 21, 2016 21:04
Show Gist options
  • Save ivanbarlog/3e2066b950e43f9f6569 to your computer and use it in GitHub Desktop.
Save ivanbarlog/3e2066b950e43f9f6569 to your computer and use it in GitHub Desktop.
Power of recursion
#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