view paper/codes/fact.c @ 122:a3ff00c33fd7 default tip

update slide
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Wed, 20 Feb 2019 12:05:38 +0900
parents 29bb4dca94ea
children
line wrap: on
line source

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

__code initialize(char* input){
    int start_number = atoi(input);
    goto fact(start_number,1);
}

__code fact(int cur,int result){
    if ( cur > 0 ){
        result *= cur;
        cur--;
        goto fact(cur,result);
    }
    goto print_fact(result);
}

__code print_fact(int result){
    printf("result = %d\n",result);
}

int main(int argc, char** argv){
    if ( argc == 1){
        printf("require arg\n");
        exit(1);
    }
    goto initialize(argv[1]);
}