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);
}
Output
0 1 1 2 3 5 8 13 21 34 55 89 144 233
Notes
* Mind the space character in both printf() statements, Lines 12 and 14. It helps 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.
Copyright © 1997-2025 by QPBC.
All rights reserved
