// a version of the Fibonacci program, using pointers
// 2019-10-10
#include <stdio.h>
#include <stdlib.h>

#define N_ELEMENTS 15

unsigned next(unsigned *fibo, unsigned index);

int main(int argc, char **argv)
{
    unsigned fibonacci[N_ELEMENTS] = { 1, 1 };
    unsigned n_numbers;

    if (argc >= 2)
        n_numbers = atoi(*(argv+1));
    else {
        printf("how many? ");
        scanf(" %u", &n_numbers);
    }
    if (n_numbers >= N_ELEMENTS)
        fprintf(stderr, "Uh-oh...too many numbers\n");

    for (unsigned i = 0; i < n_numbers; i++) {
        if (i >= 1)
            *(fibonacci + i + 1) = next(fibonacci, i);
        printf("%10u\n", *(fibonacci + i));
    }

    return 0;
}

unsigned next(unsigned *fibo, unsigned index)
{
    //return fibo[index] + fibo[ index - 1 ];
    return *(fibo + index) + *(fibo + index - 1);
}