[ create a new paste ] login | about

Link: http://codepad.org/1sH2hhIf    [ raw code | output | fork ]

appunti2 - C, pasted on May 1:
#include <stdio.h>

char *input_1 = "11";  // al posto di argv[1];

unsigned int
fibonacci (unsigned int n)
{
    unsigned int f1 = 1;
    unsigned int f0 = 0;
    unsigned int fn = n;
    unsigned int i;

    for (i = 2; i <= n; i++)
      {
        fn = f1 + f0;
        f0 = f1;
        f1 = fn;
      }

    return fn;
}

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

    sscanf (input_1, "%u", &n);

    for (i = 0; i <= n; i++)
      {
        printf ("%u ", fibonacci (i));
      }
    printf ("\n");

    return 0;
}


Output:
1
0 1 1 2 3 5 8 13 21 34 55 89 


Create a new paste based on this one


Comments: