CSC 120 Lecture 9: Lecture 9
champagnegnat971 and 18 others unlocked
26
CSC 120 Full Course Notes
Verified Note
26 documents
Document Summary
Fibonacci numbers: computing the fibonacci numbers, the fibonacci numbers (cid:2868),(cid:2869), are defined by, 2, = (cid:2869)+ (cid:2870) F0 =f1 =1: use a for-loop to compute the fibonacci numbers, the sequence is 1,1,2,3,5,8,13,21,34,55,89,144,233,377,, use 3 variables, f, fp, and fpp, (cid:449)here "p" stands for (cid:862)pre(cid:448)ious(cid:863); these (cid:448)aria(cid:271)les are long. Initialize fp = 1 and fpp = 1: for i = 2, , n, compute f as fp + fpp, print the values of i, f, and the roots. For the next round, update fpp with fp and then update fp with f: the output, the code: Computing max and min: computing max and min of numbers entered, the user specifies how many number he/she will enter, using a for-loop that makes the number of rounds equal to the number as specified by the user. In the first round, record the number entered as the current maximum and as the current minimum.