1. You may use the source code template in h3.s found in the assignment zip archive as a starting point. Let lower and upper be two positive integers with 1 ≤ lower, upper ≤ 10³ and lower ≤ upper. Let a and b be two positive integers with lower ≤ a,b ≤ upper and a ≤ b. Let x =ab. For all pairs of a and b satisfying the specified conditions, find and print the maximal value of x. For example, suppose lower = 10₁0 and upper = 1310. The algorithm will compute x for each a, b pair where 1010 max then max-x end for end for return max end function max_xor function main () unsigned int lower, max, upper SysPrintStr ("Enter lower? ") lower SysReadInt() SysPrintStr ("Enter upper? ") upper - SysReadInt () max max_xor (lower, upper) SysPrintInt (max) SysExit () end function main

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question

Program this

2 Chapter 2 Exercise: Implementing Loops
1. You may use the source code template in h3.s found in the assignment zip archive as a starting point. Let lower and
upper be two positive integers with 1 ≤ lower, upper ≤ 10³ and lower ≤ upper. Let a and b be two positive integers with lower
≤ a,b ≤ upper and a ≤ b. Let x =ab. For all pairs of a and b satisfying the specified conditions, find and print the maximal
value of x. For example, suppose lower = 10₁0 and upper = 1310. The algorithm will compute x for each a, b pair where 1010
<a,b≤13₁0 anda<b,
x = 1010 1010 1010₂1010₂=0000₂ 010x = 1010 01110101021011₂=0001₂= 110x= 1010 12 10 = 1010₂1100₂ =
0110₂=610x = 1010 1310 = 101021101₂-0111₂ = 710 X = 11101110 1011₂01011₂ - 0000₂= 010x = 11101210 = 1011₂2
1100₂ 0111₂= 710x = 1110 13 ₁0 = 1011₂1101₂= 0110₂= 6₁0x = 1210 1210 1100₂1100₂ = 0000₂=0₁0x=12101310
= 1100₂1101₂=0001₂= 110x = 1310 13 10 = 110121101₂ = 0000₂ 010
The maximal value of x is 7 when a, b = 1010, 13₁0 and a, b = 1110, 1210- The output from the program should be 7. Here is the
pseudocode for the algorithm which solves this problem,
function max_xor (lower: unsigned int, upper: unsigned int) → unsigned int unsigned int a, b, max, x
max - 0
for a lower to upper do
for b - a to
do x+a+b
if x > max then max-x end for
end for
return max
end function max_xor
function main (
unsigned int lower, max, upper SysPrintStr ("Enter lower? ") lower SysReadInt() SysPrintStr ("Enter upper? ") upper -
SysReadInt ()
max max_xor (lower, upper) SysPrintInt (max)
SysExit (
end function main
Transcribed Image Text:2 Chapter 2 Exercise: Implementing Loops 1. You may use the source code template in h3.s found in the assignment zip archive as a starting point. Let lower and upper be two positive integers with 1 ≤ lower, upper ≤ 10³ and lower ≤ upper. Let a and b be two positive integers with lower ≤ a,b ≤ upper and a ≤ b. Let x =ab. For all pairs of a and b satisfying the specified conditions, find and print the maximal value of x. For example, suppose lower = 10₁0 and upper = 1310. The algorithm will compute x for each a, b pair where 1010 <a,b≤13₁0 anda<b, x = 1010 1010 1010₂1010₂=0000₂ 010x = 1010 01110101021011₂=0001₂= 110x= 1010 12 10 = 1010₂1100₂ = 0110₂=610x = 1010 1310 = 101021101₂-0111₂ = 710 X = 11101110 1011₂01011₂ - 0000₂= 010x = 11101210 = 1011₂2 1100₂ 0111₂= 710x = 1110 13 ₁0 = 1011₂1101₂= 0110₂= 6₁0x = 1210 1210 1100₂1100₂ = 0000₂=0₁0x=12101310 = 1100₂1101₂=0001₂= 110x = 1310 13 10 = 110121101₂ = 0000₂ 010 The maximal value of x is 7 when a, b = 1010, 13₁0 and a, b = 1110, 1210- The output from the program should be 7. Here is the pseudocode for the algorithm which solves this problem, function max_xor (lower: unsigned int, upper: unsigned int) → unsigned int unsigned int a, b, max, x max - 0 for a lower to upper do for b - a to do x+a+b if x > max then max-x end for end for return max end function max_xor function main ( unsigned int lower, max, upper SysPrintStr ("Enter lower? ") lower SysReadInt() SysPrintStr ("Enter upper? ") upper - SysReadInt () max max_xor (lower, upper) SysPrintInt (max) SysExit ( end function main
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning