2.11BSD/share/learn/C/L17.1c
#print
Print the 20 Fibonacci numbers beginning with 2
(the sequence is 2,3,5,8,... where each number
is the sum of the immediately preceding pair of numbers.
Start with the pair 1,1).
Print each number on a separate line as a five digit
number (remember %3d in printf? %5d does five digits).
Compile and test your program; then type "ready".
#once #create Ref
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
#user
a.out >xxx
#cmp xxx Ref
#succeed
/* one way */
main()
{
int f1, f2, t, count;
f1 = 1;
f2 = 1;
for (count = 0; count < 20; count++) {
t = f1+f2;
f1 = f2;
f2 = t;
printf("%5d\n", t);
}
}
#log
#next
18.1a 10