7- Name: EuclidGreatestCommonDivisor (Euclid's algorithm, do not use the recursive version), Input: x, y (two natural numbers), Output: w (Greatest Common Divisor of x and y)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
icon
Related questions
Question

solve question 7 pleaseeee

Directions:
Implement the following in C++ and show the output of your code for at least two instances of the problem (All
examples come from "1.1 Introduction - Part II")
1- Name: Prime, Input: n (an integer number), Output: Prime or not prime
2- Name: SumOfNumbers, Input: n (positive integer), Output: sum (sum of all positive integers from 1 to n)
3- Name: ConvertPoundToKg, Input: weight-in-pounds (weight in pound), Output: weight-in-Kg (weight in
Kg)
4- Name: FindMinInArray, Input: T (a sequence of n numbers T[1], T[2], .., T[n]), Output: min (the
smallest number among them)
5- Name: SumDigits, Input: N (Two digit number), Output: sum (the sum of digits of N)
6- Name: GreatestCommonDivisor (simple, iterative algorithm), Input: x, y (two natural numbers), Output:
w (Greatest Common Divisor of x and y)
7- Name: EuclidGreatestCommonDivisor (Euclid's algorithm, do not use the recursive version), Input: x, y
(two natural numbers), Output: w (Greatest Common Divisor of x and y)
Trace your greatest common divisor programs for 5 iterations (problems 6 and 7), you can hand trace the code or
simply output the values from your code.
Compare the performance of the algorithms you used in problems 6 and 7.
Give an alternative algorithm for the primality test you implemented above (problem 1), describe your alternative
algorithm (you can use code or pseudocode), and compare the performance of the two algorithms.
Transcribed Image Text:Directions: Implement the following in C++ and show the output of your code for at least two instances of the problem (All examples come from "1.1 Introduction - Part II") 1- Name: Prime, Input: n (an integer number), Output: Prime or not prime 2- Name: SumOfNumbers, Input: n (positive integer), Output: sum (sum of all positive integers from 1 to n) 3- Name: ConvertPoundToKg, Input: weight-in-pounds (weight in pound), Output: weight-in-Kg (weight in Kg) 4- Name: FindMinInArray, Input: T (a sequence of n numbers T[1], T[2], .., T[n]), Output: min (the smallest number among them) 5- Name: SumDigits, Input: N (Two digit number), Output: sum (the sum of digits of N) 6- Name: GreatestCommonDivisor (simple, iterative algorithm), Input: x, y (two natural numbers), Output: w (Greatest Common Divisor of x and y) 7- Name: EuclidGreatestCommonDivisor (Euclid's algorithm, do not use the recursive version), Input: x, y (two natural numbers), Output: w (Greatest Common Divisor of x and y) Trace your greatest common divisor programs for 5 iterations (problems 6 and 7), you can hand trace the code or simply output the values from your code. Compare the performance of the algorithms you used in problems 6 and 7. Give an alternative algorithm for the primality test you implemented above (problem 1), describe your alternative algorithm (you can use code or pseudocode), and compare the performance of the two algorithms.
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Computational Systems
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