Skip to content

Instantly share code, notes, and snippets.

@mirekfranc
Created May 7, 2015 17:44
Show Gist options
  • Save mirekfranc/029de8eeafb483c2d060 to your computer and use it in GitHub Desktop.
Save mirekfranc/029de8eeafb483c2d060 to your computer and use it in GitHub Desktop.
manual tco :)
#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