C960 Discrete Math 2 Exam Questions & Answers
| Latest Already Graded A+ |Questions with
Correct Answers 2026 latest update!
C
Terms in this set (278)
1.4.3: If-else-statement 2
The condition ( x > 0 ) evaluates to true because the
value of x
1) is 2. The line abs := x is executed and the line
abs := -x is What is the value of abs after the following skipped. Therefore the final
value of abs is 2.
lines of code are
run? x := 2
If ( x > 0 )
abs := x
Else abs :=
-x End-if
,1.4.3: If-else-statement 2
The condition ( x > 0 ) evaluates to false because the
value of
2) x is -2. The line abs := x is skipped and the line abs := -x
is
What is the value of abs after the following executed. Therefore the final value of abs is -x, which is -
(-2) =
lines of code are run? 2.
x := -2
If ( x > 0 )
abs := x
Else
abs := -x
End-if
1.5.2: For-loops 1) 5
In the first iteration, i = 2. In the second iteration, i = 3. 2
+3 =5
Consider the following pseudocode
fragment: 2) 4
sum := 0 i = 2, 3, 4, 5. Four iterations
For i = 2 to 5
sum := sum + i 3) 14
End-for i = 2, 3, 4, 5. sum = 2 + 3 + 4 + 5
1) What is the value of sum after the
second
iteration?
2) How many iterations will the for-loop
execute?
3) What is the final value for sum after
executing the for-loop?
1.6.2: While-loops 1) 15
In the first iteration, count = 5. In the second iteration,
count =
product := 1 3. 5⋅3 = 15
count := 5
While ( count > 0 ) 2) 3
product := product⋅count count = 5, 3, 1. Three iterations
count := count - 2
End-while 3) 15
product = 5⋅3⋅1 = 15
1) What is the value of product after the
second iteration?
2) How many iterations will the while-
loop
execute?
3) What is the final value for product?
,1.7.2: Nested loops - example 1 1) 12
For each iteration of the outer loop, the inner loop
iterates 4
count := 0 times. The outer loop iterates 3 times. 3 × 4 = 12
For i = 1 to 3
For j = 1 to 4 2) 60
count := count + i ⋅ j 1·(1 + 2 + 3 + 4) + 2(1 + 2 + 3 + 4) + 3(1 + 2 + 3 + 4) = 60
End-
for
End-
for
1) How many times is the
variable count increased?
2)What is the final value of count?
1.7.3: Nested loops - example 2 1) 2
The initial value of j is i + 1. The final value of j is 4. j = 3,
4. 2
Consider the following pseudocode
iterations. fragment:
count := 0 2) 6
For i = 1 to 3 When i = 1, j = 2, 3, 4. When i = 2, j = 3, 4. When i = 3, j = 4. A
total
For j = i+1 to 4 of 6 iterations.
count := count + i ⋅ j
End-for 3) 35
End-for 1·(2 + 3 + 4) + 2·(3 + 4) + 3·(4) = 35
1) When i = 2, how many times
does the inner loop iterate?
2)How many times is the variable
count increased?
3) What is the final value of count?
Exercise 1.7.1: Writing algorithms in
pseudocode.
Write an algorithm in pseudocode for
each description of the input and
output.
(a)
Input: a1, a2,...,an, a sequence of
numbers, where n ≥ 1n, the length of
the sequence.Output: "True" if the
sequence is non-decreasing and
"False" otherwise.
A sequence of numbers is non-
decreasing if each number is at least
as large as the one before.
, Exercise 1.7.1: Writing algorithms in
pseudocode.
Write an algorithm in pseudocode for
each description of the input and
output.
b)
Input: a1, a2,...,an, a sequence of
numbers, where n ≥ 1 n, the length
of the sequence.
Output: "True" if there are two
consecutive numbers in the sequence
that are the same and "False"
otherwise.
Exercise 1.7.1: Writing algorithms in
pseudocode.
Write an algorithm in pseudocode for
each description of the input and
output.
c)
Input: a1, a2,...,an, a sequence of
numbers, where n ≥ 1 n, the length
of the sequence.
Output: "True" if there are any two
numbers in the sequence whose sum
is 0 and "False" otherwise.
Exercise 1.7.1: Writing algorithms in
pseudocode.
Write an algorithm in pseudocode for
each description of the input and
output.
d)
Input: a1, a2,...,an, a sequence of
numbers, where n ≥ 1n, the length of
the sequence.
Output: "True" if there are any three
numbers in the sequence that form a
Pythagorean triple.
The numbers x, y, and z are a
Pythagorean triple if x2 + y2 = z2.
| Latest Already Graded A+ |Questions with
Correct Answers 2026 latest update!
C
Terms in this set (278)
1.4.3: If-else-statement 2
The condition ( x > 0 ) evaluates to true because the
value of x
1) is 2. The line abs := x is executed and the line
abs := -x is What is the value of abs after the following skipped. Therefore the final
value of abs is 2.
lines of code are
run? x := 2
If ( x > 0 )
abs := x
Else abs :=
-x End-if
,1.4.3: If-else-statement 2
The condition ( x > 0 ) evaluates to false because the
value of
2) x is -2. The line abs := x is skipped and the line abs := -x
is
What is the value of abs after the following executed. Therefore the final value of abs is -x, which is -
(-2) =
lines of code are run? 2.
x := -2
If ( x > 0 )
abs := x
Else
abs := -x
End-if
1.5.2: For-loops 1) 5
In the first iteration, i = 2. In the second iteration, i = 3. 2
+3 =5
Consider the following pseudocode
fragment: 2) 4
sum := 0 i = 2, 3, 4, 5. Four iterations
For i = 2 to 5
sum := sum + i 3) 14
End-for i = 2, 3, 4, 5. sum = 2 + 3 + 4 + 5
1) What is the value of sum after the
second
iteration?
2) How many iterations will the for-loop
execute?
3) What is the final value for sum after
executing the for-loop?
1.6.2: While-loops 1) 15
In the first iteration, count = 5. In the second iteration,
count =
product := 1 3. 5⋅3 = 15
count := 5
While ( count > 0 ) 2) 3
product := product⋅count count = 5, 3, 1. Three iterations
count := count - 2
End-while 3) 15
product = 5⋅3⋅1 = 15
1) What is the value of product after the
second iteration?
2) How many iterations will the while-
loop
execute?
3) What is the final value for product?
,1.7.2: Nested loops - example 1 1) 12
For each iteration of the outer loop, the inner loop
iterates 4
count := 0 times. The outer loop iterates 3 times. 3 × 4 = 12
For i = 1 to 3
For j = 1 to 4 2) 60
count := count + i ⋅ j 1·(1 + 2 + 3 + 4) + 2(1 + 2 + 3 + 4) + 3(1 + 2 + 3 + 4) = 60
End-
for
End-
for
1) How many times is the
variable count increased?
2)What is the final value of count?
1.7.3: Nested loops - example 2 1) 2
The initial value of j is i + 1. The final value of j is 4. j = 3,
4. 2
Consider the following pseudocode
iterations. fragment:
count := 0 2) 6
For i = 1 to 3 When i = 1, j = 2, 3, 4. When i = 2, j = 3, 4. When i = 3, j = 4. A
total
For j = i+1 to 4 of 6 iterations.
count := count + i ⋅ j
End-for 3) 35
End-for 1·(2 + 3 + 4) + 2·(3 + 4) + 3·(4) = 35
1) When i = 2, how many times
does the inner loop iterate?
2)How many times is the variable
count increased?
3) What is the final value of count?
Exercise 1.7.1: Writing algorithms in
pseudocode.
Write an algorithm in pseudocode for
each description of the input and
output.
(a)
Input: a1, a2,...,an, a sequence of
numbers, where n ≥ 1n, the length of
the sequence.Output: "True" if the
sequence is non-decreasing and
"False" otherwise.
A sequence of numbers is non-
decreasing if each number is at least
as large as the one before.
, Exercise 1.7.1: Writing algorithms in
pseudocode.
Write an algorithm in pseudocode for
each description of the input and
output.
b)
Input: a1, a2,...,an, a sequence of
numbers, where n ≥ 1 n, the length
of the sequence.
Output: "True" if there are two
consecutive numbers in the sequence
that are the same and "False"
otherwise.
Exercise 1.7.1: Writing algorithms in
pseudocode.
Write an algorithm in pseudocode for
each description of the input and
output.
c)
Input: a1, a2,...,an, a sequence of
numbers, where n ≥ 1 n, the length
of the sequence.
Output: "True" if there are any two
numbers in the sequence whose sum
is 0 and "False" otherwise.
Exercise 1.7.1: Writing algorithms in
pseudocode.
Write an algorithm in pseudocode for
each description of the input and
output.
d)
Input: a1, a2,...,an, a sequence of
numbers, where n ≥ 1n, the length of
the sequence.
Output: "True" if there are any three
numbers in the sequence that form a
Pythagorean triple.
The numbers x, y, and z are a
Pythagorean triple if x2 + y2 = z2.