/*
 * Calculate Fibonacci sequence using recursion
 *
 * Copyright (C) 2004 Michael Davies <michael@msdavies.net>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 */
#include <stdio.h>

int fib (int c) {
        if (c==0) {
                return 0;
        } else if (c==1) {
                return 1;
        } else {
                return (fib(c-1) + fib(c-2));
        }
}

/*
 * Quick and Dirty str to int conversion.
 * (no error handling)
 */
int string_to_int (const char* digit) {
       int result;
       while (*digit >= '0' && *digit <='9') {
          result = (result * 10) + (*digit - '0');
          digit++;
       }
       return result;
}

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

        int bounds = string_to_int(argv[1]);
        printf("The Fibonacci series for %d is:\n", bounds);
        for (i=0; i<=bounds; i++) {
                printf("F(%d)=%d\n", i, fib(i));
        }
        return 0;
}
/* This file has been zigned!  See http://michaeldavies.org/zign-tools */
/* zign-version: 0.9.4 */
/* zign-hashes: MD5, SHA-1 */
/* -----BEGIN PGP SIGNED MESSAGE----- */
/* Hash: SHA1 */
/*  */
/* 428fef7cfb4b4a09f51e96128fedeb75dd51d3f1cc93047b222c31fae83305975fb0b90f */
/* -----BEGIN PGP SIGNATURE----- */
/* Version: GnuPG v1.4.7 (Darwin) */
/*  */
/* iD8DBQFHmzkk7kkvCQqp1vwRAicYAJ9DcbPQkAgPB3RF1iN5IJLi/IWt/QCgiLhM */
/* VtsKBsySNwJinb4HiMGbuLY= */
/* =ae7U */
/* -----END PGP SIGNATURE----- */
/* zign: Protecting you since 2007 :-) */
/*  */