summaryrefslogtreecommitdiff
path: root/usr.bin/learn/lib/C/L17.1c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/learn/lib/C/L17.1c')
-rw-r--r--usr.bin/learn/lib/C/L17.1c50
1 files changed, 50 insertions, 0 deletions
diff --git a/usr.bin/learn/lib/C/L17.1c b/usr.bin/learn/lib/C/L17.1c
new file mode 100644
index 00000000000..c7eb76ce64b
--- /dev/null
+++ b/usr.bin/learn/lib/C/L17.1c
@@ -0,0 +1,50 @@
+#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