One of the first algorithms written in a book is known as the Euclidean algorithm. It...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
One of the first algorithms written in a book is known as the Euclidean algorithm. It describes a method for finding the Greatest Common Divisor (GCD) of two positive integers. The GCD of two integers can help to reduce a fraction to a proper form (for example, 9/12 reduces to 3/4). In school you likely learned another method called factorization to do this that is, you factored the two integers and then reduced the fraction by crossing out common terms. Description of GCD Euclidean Algorithm 1. Start with two positive integers. 2. Replace the larger integer with the difference of the two integers. 3. Repeat the second step until the two integers are the same (this value is the GCD). Example of Euclidean Algorithm (18, 6)-> (12, 6)-> (6, 6) Detailed remarks: Initial pair of values: (18, 6) LOOP: next step, replace the larger value, 18, with (186) or 12 resulting in (12, 6) LOOP: next step, replace the larger value, 12, with (126) or 6 resulting in (6, 6) LOOP: stop the loop since the two values in the pair (6, 6) are the same. Therefore, the GCD of (18, 6) is 6. Write a C++ program that asks the user to enter a fraction (HINT: checkpoint 3.5). The program should implement the GCD algorithm described above to then reduce the fraction. The output of the program should show the original fraction, the reduced fraction and the computed GCD. Show the following three test cases with your screen shots: 3 / 12 1386 / 3213 105 / 252 One of the first algorithms written in a book is known as the Euclidean algorithm. It describes a method for finding the Greatest Common Divisor (GCD) of two positive integers. The GCD of two integers can help to reduce a fraction to a proper form (for example, 9/12 reduces to 3/4). In school you likely learned another method called factorization to do this that is, you factored the two integers and then reduced the fraction by crossing out common terms. Description of GCD Euclidean Algorithm 1. Start with two positive integers. 2. Replace the larger integer with the difference of the two integers. 3. Repeat the second step until the two integers are the same (this value is the GCD). Example of Euclidean Algorithm (18, 6)-> (12, 6)-> (6, 6) Detailed remarks: Initial pair of values: (18, 6) LOOP: next step, replace the larger value, 18, with (186) or 12 resulting in (12, 6) LOOP: next step, replace the larger value, 12, with (126) or 6 resulting in (6, 6) LOOP: stop the loop since the two values in the pair (6, 6) are the same. Therefore, the GCD of (18, 6) is 6. Write a C++ program that asks the user to enter a fraction (HINT: checkpoint 3.5). The program should implement the GCD algorithm described above to then reduce the fraction. The output of the program should show the original fraction, the reduced fraction and the computed GCD. Show the following three test cases with your screen shots: 3 / 12 1386 / 3213 105 / 252
Expert Answer:
Answer rating: 100% (QA)
To find all the functional dependencies that are satisfied by the given relation we need to analyze ... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
Googles ease of use and superior search results have propelled the search engine to its num- ber one status, ousting the early dominance of competitors such as WebCrawler and Infos- eek. Even later...
-
EXECUTIVE SUMMARY In this report, there is an in-depth analysis of logistics revolving around a case study based on an article by Emmanuel Hassoun, a supply chain professional and Pierre Mawet, a...
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
Verify that (x, y) = tan 1 y/x is harmonic using both the rectangular and polar expressions for .
-
A copper strip (n = 8.47 1022 electrons per cubic centimeter) 2 cm wide and 0.1 cm thick is used to measure the magnitudes of unknown magnetic fields that are perpendicular to the strip. Find the...
-
A person with a(n) ____________ personality would most likely act unemotionally and manipulatively when trying to influence others to achieve personal goals. (a) extraverted (b) sensation-thinking...
-
Explain how the control variate technique is implemented.
-
Presented below are the financial statements of Kurtzel Company. Additional data: 1. Depreciation expense was $17,500. 2. Dividends declared and paid were $20,000. 3. During the year equipment was...
-
An ATV has an average acceleration of 1.9 m/s 2 . If the vehicle accelerates for 5.8 s and has an initial velocity of 15 m/s [E], what is the final velocity of the ATV?
-
Read the Workplace Policies and Procedures Example - Pinkies Pizza and Pasta A: You witness a fellow staff member cough into his hand. The staff member then picks up pre-made sandwiches (without...
-
what would a value proposition canvas look like for a banana chips company that has all these qualities to offer. 1. Our products are produced of the highest quality, grown from the soils of the...
-
John Doe has decided to clone himself. He is sterile. He cannot find anyone to marry him. He wishes to have children. He knows that he will not be able to love a child who is adopted or not connected...
-
What are some of the outcomes, when you do not have ethical leadership in a Criminal Justice organization?
-
My Annual Comprehensive Financial Report is on Delaware state and pls include references. 1. Explore the concepts of the course material relating to ACFRs. You must also find and review / read...
-
With the capabilities that informatics brings to the health care sector come the responsibility of considering the legal and ethical outcomes of using patient data, even if anonymous, to inform...
-
Define the following terms: incremental cost, opportunity cost, and sunk cost. 13-5 "Variable costs and differential costs mean the same thing." Do you agree? Explain. 13-6 "All future costs are...
-
A. Please find the angle 8 between the vectors in radians u = < 1,1 >, v = < 2, -2> B. Please find the projection of u onto v. u = < 6,7 >, v = < 1,4 > C. Please find u * v. u=- 2i + 4j, v = 3i + 2j...
-
Time Travel Publishing was recently organized. The company issued common stock to an attorney who provided legal services worth $25,000 to help organize the corporation. Time Travel also issued...
-
Coupon collector is a classic statistics problem with many practical applications. The problem is to pick objects from a set of objects repeatedly and find out how many picks are needed for all the...
-
Write a GUI program for Programming Exercise 8.19, as shown in Figure 16.49a?b. Let the user enter the numbers in the text fields in a grid of 6 rows and 7 columns. The user can click the Solve...
-
The gcd(m, n) can also be defined recursively as follows: If m % n is 0, gcd(m, n) is n. Otherwise, gcd(m, n) is gcd(n, m % n). Write a recursive method to find the GCD. Write a test program that...
-
In the Application A Beer Manufacturer's ShortRun Cost Curves," the short-run variable cost function for Japanese beer is \(V C=0.55 q^{1.67}\). If the fixed cost is 600 and the firm produces 550...
-
A firm's production function is \(q=K^{0.4} L^{0.6}\). What is the firm's cost-minimizing input bundle when \(w=3\) and \(r=4\) ? Draw a diagram depicting the firm's long-run expansion path. What is...
-
If a competitive firm's cost increases due to an increase in the price of a factor of production or a tax, the firm's manager can quickly determine by how much to adjust output by calculating how the...
Study smarter with the SolutionInn App