## Monday, October 6, 2003

### Computer Science: Fibonacci numbers

Here is what I started out doing my first year of College:

*
* This program computes and displays the first eight Fibonacci numbers
*/

#include

void main ()
{
int   a, b, c, d, e, f, g, h;
a=1;
b=1;
c=a+b;
d=b+c;
e=c+d;
f=d+e;
g=e+f;
h=f+g;

printf("The first eight Fibonacci numbers are: %d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h);
}

/*
* This program finds the first eight Fibonacci numbers
*/
#include

main (void)
{
int Fib0, Fib1, Fib2, Fib3, Fib4, Fib5, Fib6, Fib7, Fibn, n;
fibonacci(int n);
printf("Please input the value 'n' for the Fibanocci Sequence ->");
scanf("%d", &n);
Fibn = fibonacci(n-1) + fibonacci(n-2);
printf("The first (%d) values in the Fibanocci sequence are,\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d",n,Fib0,Fib1,Fib2,Fib3,Fib4,Fib5,Fib6,Fib7);
}

/*
* This program finds the first eight Fibonacci numbers
*Pre: n > 0
*/
#include

main (void)
int Fib0, Fib1, Fib2, Fib3, Fib4, Fib5, Fib6, Fib7, n;
Fib0 = n+1;
Fib1 = n+1;
Fib2 = n+2;
Fib3 = n+3;
Fib4 = n+5;
Fib5 = n+8;
Fib6 = n+13;
Fib7 = n+21;
printf("The first eight values in the Fibonacci sequence are,\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d",Fib0,Fib1,Fib2,Fib3,Fib4,Fib5,Fib6,Fib7);
}

/*
* This program finds the first eight Fibonacci numbers
*/
#include

main (void)
{
int a, b, c, d, e, f, g, za, zb, zc, zd, ze, zf, zg, zh, n;
printf("Please input the value 'n' for the Fibanocci Sequence ->");
scanf("%d", &n);
a=1;
b=2;
c=3;
d=4;
e=5;
f=6;
g=7;
za=(a)+(0);
zb=(0)+(a);
zc=(b)+(0);
zd=(c)+(a);
ze=(d)+(b);
zf=(e)+(c);
zg=(f)+(d);
zh=(g)+(e);
printf("The first eight values in the Fibanocci sequence are,\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d",za,zb,zc,zd,ze,zf,zg,zh);
}

/*
* This program finds the first eight Fibonacci numbers
*/
#include

main (void)
{
int a, b, c, d, e, f, g, h, za, zb, zc, zd, ze, zf, zg, zh, n;
printf("Please input the value 'n' for the Fibanocci Sequence ->");
scanf("%d", &n);
a=n-8;
b=n-7;
c=n-6;
d=n-5;
e=n-4;
f=n-3;
g=n-2;
h=n-1;
za=a+1;
zb=a+b;
zc=c+a;
zd=(d-2)+(d-1);
ze=(e-2)+(e-1);
zf=(f-2)+(f-1);
zg=(g-2)+(g-1);
zh=(h-2)+(h-1);
printf("The first eight values in the Fibanocci sequence are,\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d",za,zb,zc,zd,ze,zf,zg,zh);
}