0% found this document useful (0 votes)
694 views7 pages

Midterm Answers

This document contains a 20 question mid-term test for CS 40A that covers topics like: 1. Converting between number bases 2. Simplifying mathematical expressions 3. Filling in tables based on pseudocode instructions 4. Determining the final values of variables after sequences of assignment statements 5. Identifying the purpose of algorithms The questions require skills like decimal to binary conversion, order of operations, variable assignment, conditional logic, and analyzing pseudocode.

Uploaded by

Mt Rush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
694 views7 pages

Midterm Answers

This document contains a 20 question mid-term test for CS 40A that covers topics like: 1. Converting between number bases 2. Simplifying mathematical expressions 3. Filling in tables based on pseudocode instructions 4. Determining the final values of variables after sequences of assignment statements 5. Identifying the purpose of algorithms The questions require skills like decimal to binary conversion, order of operations, variable assignment, conditional logic, and analyzing pseudocode.

Uploaded by

Mt Rush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

CS 40A MID-TERM TEST

HOWARD DACHSLAGER

NAME: ---------------------- STUDENT # -------------------IMPORTANT: No partial credit given. Assume no typing, logical or syntax errors on my part.
1. Convert 66057 => n 8 = ___________

4465

2. Convert 2403115 => n16 = ___________ 227F

3. Convert 23615119 => n16 = ___________138A1B


4. By matching convert the below binary number to the base 8:
1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 1 0 11 0 1 11 0 0 11 0 1 0 1 0 1 12 => n8 = ____________
155567334653.
5. Simplify : (1347 + 21317)*1017 = n16 = ____________
6. 532910 => n3 = ____________

21022101

7. (104)5 - 1 = n4 = ___________

33333

A24E

=> n16 = _________ 3FF

8.
8. Convert 45AF16 => N3. ____________

220110201

9. Complete this table. Make sure all cells that contain numbers are filled.
PSEUDO-CODE INSTRUCTIONS

X := 7

Y := -12

-12

Z := 13

-12

13

IF (X + Y + Z) <> X*Y THEN

-12

13

BEGIN

-12

13

X : = (X Y) X

-12

13

Y := X 3 * Y

38

13

Z:=X+5

38

END

38

IF (X - Y + Z) <> X +Y THEN

38

BEGIN

38

X : = 2 * (X Y) X

-36

38

Y := X 3 * Z

-36

-57

Z:=X+2

-36

-57

-34

END

-36

-57

-34

10. (2123 + 22223)*1013 => n10 = _____________ 1030


11. The instructions
X := 3
X :=X*X
X :=X+X
X :=X*X
will cause the final value of X to be _________ 324
12.
X := 12
Y := 15
Z := 5
Z := X
X := Y
Y := Z
The above sequence of commands will exchange the values in the variables, resulting finally in
X= _____; Y = ______;
Z = __________
x= 15

y= 12

, z= 12

13.

W:=7
U:= 2
W:= 5 + (W*(W + UW) + 2)2
T := W
The above sequence of instructions will store ________ 30

in T

14.
X := 3
X := 2*X - X
X := 2*X + X
X := 2*X - X
X := 2*X + X
X := 2*X - X
X := 2*X + X
Y := 2*X
The above sequence of instructions will store ________

162 in Y.

15.
IF X < 0 THEN
BEGIN
X : = -1*X
END
IF 2*(X2) <> X THEN
BEGIN
X := X - 1
END
ELSE
BEGIN
X:=X+1
END

The purpose of writing the above algorithm is


If X is negative, make it positive. If X is odd, subtract one from X;
If X is negative, make it positive. If X is even, add one to X.
(a.) TRUE

(b.) FALSE

(A)

16.
Complete the table below. Make sure you fill in all cells that contain numbers.
PSEUDO-CODE INSTRUCTIONS

X1

X2

X3

COUNT

X1 := 5

X2 := 12

12

X3 := -2

12

-2

COUNT := 0

12

-2

IF X1 < 0 THEN
BEGIN
COUNT := COUNT + 1
END

12

-2

IF X2 < 0 THEN
BEGIN
COUNT := COUNT + 1
END

12

-2

IF X3 < 0 THEN
BEGIN
COUNT := COUNT + 1
END

12

-2

17.
Complete the following table. Make sure all cells that contain numbers are filled.
PSEUDO-CODE INSTRUCTIONS

N10

N8

N10 := 2304

2304

BASE := 8

2304

N8 := 0

2304

K:=0

2304

R := N10 MOD BASE

2304

Q:= (N10 - R)BASE

2304

BASE

288

8
0

N8:= N8 + R*10^K

2304

288

N10 := Q

288

288

K := K + 1

288

288

R := N10 MOD BASE

288

288

Q:= (N10 - R)BASE

288

36

N8 := N8 + R*10^K

288

36

N10 := Q

36

36

K := K + 1

36

36

R := N10 MOD BASE

36

36

Q:= (N10 - R)BASE

36

N8 := N8 + R*10^K

36

400

N10 := Q

400

K := K + 1

400

R := N10 MOD BASE

400

Q:= (N10 - R)BASE

400

N8:= N8 + R*10^K

4400

4400

4400

N10 := Q
K := K + 1

18. What is the purpose of writing the following algorithm:


T := N1
IF N2 < T THEN
BEGIN
T := N2
END
IF N3 <T THEN
BEGIN
T := N3
END
Z := T
(a.). To assign the lowest value to Z
(b.) To assign the highest value to Z
A.
19. What does the programmer what to find out from the following algorithm:
IF 2*(X2) = X THEN
BEGIN
EVEN := 1
END
IF 2*(X2) <> X THEN
BEGIN
ODD:= 1
END
____________________________________________
:

To find if a number is even or odd.

20.
Complete the following table. Make sure all cells with numbers are filled.
INSTRUCTIONS
X1:= 7

X1
7

X2

X2:= 2

X:3= 10

10

IF X1 < X2 THEN

10

BEGIN

10

TEMP := X1

10

X3

TEMP

X1 := X2

10

X2 := TEMP

10

END

10

IF X2 < X3 THEN

10

BEGIN

10

TEMP := X2

10

X2 := X3

10

10

X3 := TEMP

10

END

10

You might also like