Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Recursion without recursion... or is it?

Name: Anonymous 2011-06-15 22:03

This works on 32-bit x86 Linux with gcc as long as you don't enable optimization.


#include <stdio.h>
#include <stdlib.h>

static void factorial(int in, int *out) {
        *(&in-1)-=5-5*(1/in);
        *out*=in--;
}

int main(int argc, char **argv) {
        int result=1;
        int number=0;

        if(argc!=2) {
                exit(1);
        }

        number=atoi(argv[1]);

        if(number<1) {
                exit(2);
        }

        factorial(number, &result);

        printf("%d! = %d\n", number, result);

        return 0;
}

$ ./factorial 3
3! = 6
$ ./factorial 5
5! = 120

Name: VIPPER 2011-06-16 12:09

>>19
You are not a true VIPPER.
The redditers are imageboard scum and should be treated like that.

As for you >>19san, you do not deserve the tag of VIPPER, i hope you will burn in hell.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List