News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Fibonacci Series Using an Array

Started by jayanthi mandhalapu, Jul 27, 2009, 08:22 AM

Previous topic - Next topic

jayanthi mandhalapu


#include <stdio.h>

main()
{       int fib[24];
        int i;

        fib[0] = 0;
        fib[1] = 1;

        for(i = 2; i < 24; i++)
                fib = fib[i-1] + fib[i-2];

        for (i = 0; i < 24; i++)
                printf("%3d   %6d\n", i, fib);
}

One new construct has been introduced here.

int fib[24];
This defines an array called fib of 24 integers. In C, the array index is bounded by square brackets (this avoids confusion with a function call). Also, the first element of the array has index zero, and for this 24 element array, the last element is index 23.
Be Happy And Always Remain So