ercise 1: (Design of algorithm to find greatest common divisor) In mathematics, the greatest common divisor (gcd) of two or more integers is the largest positive integer that divides each of the integers. For example, the gcd of 8 and 12 is 4. Why? Divisors of 8 are 1, 2, 4, 8. Divisors of 12 are 1, 2, 4, 6, 12 Thus, the common divisors of 8 and 12 are 1, 2, 4. Out of these common divisors, the greatest one is 4. Therefore, the greatest common divisor (gcd) of 8 and 12 is 4. Write a programming code for a function FindGCD(m,n) that find the greatest common divisor. You can use any language of Java/C++/Python/Octave. Find GCD Algorithm: Step 1 Make an array to store common divisors of two integers m, n. Step 2 Check all the integers from 1 to minimun(m,n) whether they divide both m, n. If yes, add it to the array. Step 3 Return the maximum number in the array. 7

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 12PE
icon
Related questions
Question
Exercise 1: (Design of algorithm to find greatest common divisor)
In mathematics, the greatest common divisor (gcd) of two or more integers
is the largest positive integer that divides each of the integers.
For example, the gcd of 8 and 12 is 4. Why?
Divisors of 8 are 1, 2, 4, 8.
Divisors of 12 are 1, 2, 4, 6, 12
Thus, the common divisors of 8 and 12 are 1, 2, 4.
Out of these common divisors, the greatest one is 4. Therefore, the greatest
common divisor (gcd) of 8 and 12 is 4.
Write a programming code for a function FindGCD(m,n) that find the greatest
common divisor. You can use any language of Java/C++/Python/Octave.
Find GCD Algorithm:
Step 1 Make an array to store common divisors of two integers m, n.
Step 2 Check all the integers from 1 to minimun(m,n) whether they divide
both m, n. If yes, add it to the array.
Step 3 Return the maximum number in the array.
Transcribed Image Text:Exercise 1: (Design of algorithm to find greatest common divisor) In mathematics, the greatest common divisor (gcd) of two or more integers is the largest positive integer that divides each of the integers. For example, the gcd of 8 and 12 is 4. Why? Divisors of 8 are 1, 2, 4, 8. Divisors of 12 are 1, 2, 4, 6, 12 Thus, the common divisors of 8 and 12 are 1, 2, 4. Out of these common divisors, the greatest one is 4. Therefore, the greatest common divisor (gcd) of 8 and 12 is 4. Write a programming code for a function FindGCD(m,n) that find the greatest common divisor. You can use any language of Java/C++/Python/Octave. Find GCD Algorithm: Step 1 Make an array to store common divisors of two integers m, n. Step 2 Check all the integers from 1 to minimun(m,n) whether they divide both m, n. If yes, add it to the array. Step 3 Return the maximum number in the array.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr