CS 60 Slides - PowerPoint PPT Presentation

About This Presentation
Title:

CS 60 Slides

Description:

L long double. type. d decimal integers. u unsigned (decimal) ints. o ... f doubles (floats are cast) e doubles (exp. notation) g f or e, if exp -3 or -4 ... – PowerPoint PPT presentation

Number of Views:12
Avg rating:3.0/5.0
Slides: 8
Provided by: Kel7163
Learn more at: https://www.cs.hmc.edu
Category:
Tags: doubles | slides

less

Transcript and Presenter's Notes

Title: CS 60 Slides


1
Binary multiplication
define Sj (strlen(B)-j-1) define Si
(strlen(A)-i-1) int main() int i, T1000
char A300, B300 while (cin gtgt A gtgt B)
for (i0 ilt1000 i) Ti 0 for
(i0 Ai ! 0 i) if (ASi
'1') for (int j0 Bj ! 0 j)
if (BSj '1') T999-i-j
/ add columns / / then simplify and
print /
1001110 times 11001
create a table
0000000000001001110 0000000000000000000 000000
0000000000000 0000000001001110000 0000000010011100
000
0000000011013211110
add the columns
0000000011110011110
simplify
STL http//www.sgi.com/Technology/STL
2
Fraction calculator
getNum() getOp() operate(n1,d1,n2,d2,op) simplif
y(int n,int d)
functions to help parse...
gets a number or returns an error
gets an operator or returns an error
does the arithmetic
reduces n/d to lowest terms
18 - --5 / 7 3 1 - 3 ...
evaluate as you go
getNum()
when you see this, catch up with any pending
operations
getOp()
18 -
15/7
pending
immediate
111/7
pending
3
C Output
printf, fprintf, sprintf(char s, const char
format, )
the destination
the format string
the values
possible format strings
h
.4
12
-0

d
d decimal integers u unsigned (decimal)
ints o octal integers x hexadecimal
integers f doubles (floats are cast) e
doubles (exp. notation) g f or e, if exp lt -3
or -4 c character s string n outputs of
chars written !! two of these print a
type
size modifier
minimum field width
precision
allowed size modifiers
flags
- left-justify 0 pad w/ zeros
use sign ( or -) (space) use sign ( or -)
deviant operation
h short l long (lowercase L) L long double
start character
4
C Output
value 42
value -42
10.4d
0042
-0042
-12x
0x2a
0xffffffd6
value 42
value -42.419
10.4g
42
-42.42
- 10.4g
42
-42.42
-10.4g
42.00
-42.42
value forty-two
10.5s
forty
5
Stuff Id never heard of...
sprintf(s,.f,width,prec,number)
if width 10, prec 4, and number
3.14159, then
s 3.142
What if you want to know how much was written to
s ?
sprintf(s,.f n,width,prec,number,n)
after which
n 11
6
Bugs No Bugs
include ltstdio.hgt char T"IeJKLMaYQCEjbZRskcS
ldUV\\X\\/_ltlt90!\"434-./2gts", K31000,F,
x,A,M2,J,r4,g,N,Y,Q,W,k,q,DX()r
r r3M1-(x1)rW,1,2Q2,1x1Y,g
((((x 7) -1)gtgt1)-1)?rrxgtgt3,(xltr)X()
E()AX(x0,g J ),x7(TgtgtA3),J(xF-W
-x)A7Qx3A(M)2
( x1),gJ((xk-W)A7)-A,g1(M)gMTA
,1 x1,x1,(A1)(E(),JW)l()
E(--ql () )B()JB((DJ,Q2ltD
Dltk1(g1
), !(D-WD-9D-10D-13)(!r(g0)
, r1)64ltDDlt91(r0,gD-63)
D gt 97Dlt123(r0,gD-9
5)!(D-k
3 )(r0,g12)Dgtk3Dltk
1 -1(r0,gD-47),J))j(
) putchar(A)b()(j(A(K)
D
W r2Yx),xltY)b()t
() (j((b(Dqg,x0),AW)
), qlt((r1)ltY?(r1)

Y) )t()R()(A(t(
q 0),'\n'),j(),r
2 ltN)R()O()
( j((r20,R(

)) ),r1-q)
O(g--q)
C()(
J gets

(K 1))C((B(gK2),r!(!r(g0)),(r)r
g-K2,gK2 ,r 1 O()) ) main ()C ((l( (
J( A0) K, AM (F (k( M!A (Q T( q(Y
(W 32)- (N4 )))) N) 2)7 )7) ),Y Nltlt( r! -
A)) )
class Line Point p1 Point p2
Line(Point p1, Point p2) p1 new
Point() p2 new Point() this.p1 p1
this.p2 p2 // other methods
2000 IOCCC winner Best use of flags
www.cs.hmc.edu/dodds/anderson.c
7
Power Towers
20000 3
Input
n b
Idea
Write n in base b -- including all exponents!
9
2
5
3
20000 3 3 23 23 2
Output
2 3 32 3 2 20000 3
3 23 23 2
Write a Comment
User Comments (0)
About PowerShow.com