view protoGenCheck/fibonacci.c @ 8:37a10fd62ea9

add programs for prototype generation checking
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Sat, 21 Feb 2015 21:19:46 +0900
parents
children
line wrap: on
line source

/*
  calculate fibonacci progression.
  Author : Kaito Tokumori
*/

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

__code fibonacci(int loop);
__code calcLoop(int before, int current, int loop);
__code print_answer(int answer);

int main(int argc, char **argv) {
  int i;
  i = atoi(argv[1]);

  goto fibonacci(i);
}

__code fibonacci(int loop) {
  goto calcLoop(0, 1, loop);
}

__code calcLoop(int before, int current, int loop) {
  if ( loop > 1) {
    goto calcLoop(current, before+current, loop-1);
  }else{
    goto print_answer(current);
  }
}

__code print_answer(int answer) {
  printf("factorial = %d\n",answer);
  exit(0);
}