Generate the first 15 Fibonacci numbers with for loop - C Statement

C examples for Statement:for

Description

Generate the first 15 Fibonacci numbers with for loop

Demo Code

#include <stdio.h>

int main (void)
{
    int Fibonacci[15];
    //www  .ja  v  a  2 s.  c  om
    Fibonacci[0] = 0;   // by definition
    Fibonacci[1] = 1;   // by definition
    
    for (int i = 2; i < 15; ++i)
        Fibonacci[i] = Fibonacci[i - 2] + Fibonacci[i - 1];
        
    for (int i = 0; i < 15; ++i)
        printf ("%i\n", Fibonacci[i]);
    
    return 0;
}

Result


Related Tutorials