Design and develop a solution with functions (modules) and control structures for a program that finds the greatest common divisor (GCD) of positive integers x and y. The Euclidean algorithm for finding the GCD of x and y is defined as follows: • if y is greater than x, then exchange x and y; • divide x by y and get the remainder r; if r is equal to 0, then GCD(x, y) is y; stop the loop. • replace x by y and replace y by r; return to the previous step.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Answer as much as you can

Part B - Finding Greatest Common Divisor (GCD)
Design and develop a solution with functions (modules) and control structures for a program
that finds the greatest common divisor (GCD) of positive integers x and y.
The Euclidean algorithm for finding the GCD of x and y is defined as follows:
• if y is greater than x, then exchange x and y;
• divide x by y and get the remainder r; if r is equal to 0, then GCD(x, y) is y; stop the
loop.
• replace x by y and replace y by r; return to the previous step.
For example, finding GCD of 36 and 78:
x = 36, y = 78
y > x, exchange x and y.
x = 78, y = 36;
78/36 = 2 with a remainder of 6, r + 0; x becomes 36, y becomes 6.
x = 36, y = 6,
36/6 = 6 with a remainder of 0, r = 0; answer is y = 6.
Provide screenshot of the program run in the answer script if your developed program produces
the expected output. Note that you are required to maintain a good program style when
developing your C++ program. Program style refers to things that make your program easy to
read and understand but do not affect the execution of the program. Follow the advice given
for placing whitespaces to improve readability, choosing good user-defined identifiers and
giving comments that are relevant and liberally, but not to excess.
Part B- Assessment
Part 1- Program Design Elements
i.
Construct a structure chart with data flow and execution of conditional and loops for
program design.
ii.
Construct a flowchart for the Euclidean Algorithm to illustrate the execution flow of
the process.
Part 2 - Use of Selection and Loop Control Structures
The following processes/modules will be assessed:
i.
The module that reads x and y.
ii.
The module that finds GCD using the Euclidean algorithm.
iii.
The module that prints GCD.
Transcribed Image Text:Part B - Finding Greatest Common Divisor (GCD) Design and develop a solution with functions (modules) and control structures for a program that finds the greatest common divisor (GCD) of positive integers x and y. The Euclidean algorithm for finding the GCD of x and y is defined as follows: • if y is greater than x, then exchange x and y; • divide x by y and get the remainder r; if r is equal to 0, then GCD(x, y) is y; stop the loop. • replace x by y and replace y by r; return to the previous step. For example, finding GCD of 36 and 78: x = 36, y = 78 y > x, exchange x and y. x = 78, y = 36; 78/36 = 2 with a remainder of 6, r + 0; x becomes 36, y becomes 6. x = 36, y = 6, 36/6 = 6 with a remainder of 0, r = 0; answer is y = 6. Provide screenshot of the program run in the answer script if your developed program produces the expected output. Note that you are required to maintain a good program style when developing your C++ program. Program style refers to things that make your program easy to read and understand but do not affect the execution of the program. Follow the advice given for placing whitespaces to improve readability, choosing good user-defined identifiers and giving comments that are relevant and liberally, but not to excess. Part B- Assessment Part 1- Program Design Elements i. Construct a structure chart with data flow and execution of conditional and loops for program design. ii. Construct a flowchart for the Euclidean Algorithm to illustrate the execution flow of the process. Part 2 - Use of Selection and Loop Control Structures The following processes/modules will be assessed: i. The module that reads x and y. ii. The module that finds GCD using the Euclidean algorithm. iii. The module that prints GCD.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Public key encryption
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education