Created
May 7, 2015 17:44
-
-
Save mirekfranc/029de8eeafb483c2d060 to your computer and use it in GitHub Desktop.
manual tco :)
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> | |
#include <stdlib.h> | |
static int | |
factorial_helper (int n, int a) | |
{ | |
start: | |
a *= n; | |
if (n-- > 1) | |
goto start; | |
return a; | |
} | |
int factorial (int n) { return factorial_helper (n, 1); } | |
int | |
main (int argc, char **argv) | |
{ | |
if (argc < 2) | |
return 1; | |
printf ("%d\n", factorial (atoi (argv[1]))); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment