Solution for Exercise 9-16

ex0916

#include <stdio.h>

int main()
{
    int fibo,nacci;

    fibo=0;
    nacci=1;

    do
    {
        printf("%d ",fibo);
        fibo=fibo+nacci;
        printf("%d ",nacci);
        nacci=nacci+fibo;
    } while( nacci < 300 );

    putchar('\n');
    return(0);
}

Notes

* Mind the space character in both printf() statements, Lines 12 and 14. They help make the output readable.

* A Fibonacci sequence is both mathematic and natural phenomena. It starts with the values 0 and 1, as defined in the code at Lines 7 and 8. The next number is generated by adding the previous two. That's the action that takes place in the do-while loop.