hw8
7.14
Given the two functions (in C syntax):
int cube (int x) { return x*x*x; }
int sum (int x, int y, int z) { return x + y + z; }
describe the process of normal order evaluation of the expression
sum(cube(2), cube(3), cube(4)), and compare it to applicative order
evaluation. In particular, how many additions and multiplications are
performed using each method?
7.32
Describe the effect of the FORTRAN "spaghetti code" of Figure 7.6,
Section 7.4. Write c/c++ statements without GOTOs that equivalent
it. If not, explain why not.
Figure 7.6
IF (X.GT.O) GOTO 10
IF (X.LT.O) GOTO 20
X = 1
GOTO 30
10 X= X + 1
GOTO 30
20 X= -X
GOTO 10
30 CONTUNUE
Given the two functions (in C syntax):
int cube (int x) { return x*x*x; }
int sum (int x, int y, int z) { return x + y + z; }
describe the process of normal order evaluation of the expression
sum(cube(2), cube(3), cube(4)), and compare it to applicative order
evaluation. In particular, how many additions and multiplications are
performed using each method?
7.32
Describe the effect of the FORTRAN "spaghetti code" of Figure 7.6,
Section 7.4. Write c/c++ statements without GOTOs that equivalent
it. If not, explain why not.
Figure 7.6
IF (X.GT.O) GOTO 10
IF (X.LT.O) GOTO 20
X = 1
GOTO 30
10 X= X + 1
GOTO 30
20 X= -X
GOTO 10
30 CONTUNUE
留言
張貼留言