CSC 120 Lecture 10: Lecture 10
champagnegnat971 and 18 others unlocked
26
CSC 120 Full Course Notes
Verified Note
26 documents
Document Summary
Lecture 10: printf allows specification of how the data is printed by inserting information between the. In the case of %s (that is, string: - is for flushing left an integer before s means the space allocated. Special characters: to i(cid:374)(cid:272)lude a "%" as a (cid:272)hara(cid:272)ter to pri(cid:374)t i(cid:374) the for(cid:373)at string, use %, also, you can specify the newline character with %n, for example, system. out. printf( "%. 2f%%%n", 4. 1234 ) produces the output of. F0 =f1 =1: 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" sta(cid:374)ds 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, compute the square and cubic roots of f, sqroot and cbroot, print the i, f, and the roots. For the next round, update fpp with fp and then update fp with f: output: "%5d" for the i: 20 character spaces for f: