• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 93 pages
Exam (elaborations)

C960 Discrete Math 2 | Full Questions, Correct Answers, and Worked Solutions | 2026 Update | 100% Correct.

Document preview thumbnail
Preview 4 out of 93 pages

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

Content preview

Western Governors University D 281




C960 Discrete Math 2 |
Full Questions, Correct
Answers, and Worked
Solutions | 2026 Update |
100% Correct.
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.

Document information

Uploaded on
August 5, 2026
Number of pages
93
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$13.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Cleverman
5.0
(1)
Sold
5
Followers
1
Items
1691
Last sold
2 weeks ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions