answersLogoWhite

0


Best Answer

You achieve this by putting all the values in container that allows linear traversal, such as an array. If the array has no numbers at all, the greatest common factor is 0. if the array has one number, the greatest common factor is that number. For arrays with two or more numbers, pop the last two numbers and calculate their greatest common factor, pushing the result back onto the array. Repeat until there is only one number left in the array. That number is the greatest common factor of all the original numbers.

To implement this, you will need a function that can return the greatest common factor of any two values. The following shows one way to implement this function:

unsigned greatest_common_factor (unsigned a, unsigned b)

{

while (a!=b)

a>b?a-=b:b-=a;

return a;

}

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program to find the greatest common factor of a set of numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

The greatest factor that two or more numbers have common is the greatest common factor or what?

The greatest factor that two or more numbers have in common is known as the greatest common factor, or GCF.


What is the greatest common factor for 28?

There cannot be a greatest common factor if there are not at least two numbers to compare. The greatest common factor is the largest factor that all the numbers have in common - the largest factor that they all share.


What is the greatest common factor for 712?

There cannot be a greatest common factor if there are not at least two numbers to compare. The greatest common factor is the largest factor that all the numbers have in common - the largest factor that they all share.


What is the greatest common factor of 270?

There cannot be a greatest common factor if there are not at least two numbers to compare. The greatest common factor is the largest factor that all the numbers have in common - the largest factor that they all share.


Greatest common factor of 42?

There cannot be a greatest common factor if there are not at least two numbers to compare. The greatest common factor is the largest factor that all the numbers have in common - the largest factor that they all share.


What is the greatest common factor of 374?

There cannot be a greatest common factor if there are not at least two numbers to compare. The greatest common factor is the largest factor that all the numbers have in common - the largest factor that they all share.


What is the greatest common factor of 410?

There cannot be a greatest common factor if there are not at least two numbers to compare. The greatest common factor is the largest factor that all the numbers have in common - the largest factor that they all share.


What is greatest common factor of 39?

There cannot be a greatest common factor if there are not at least two numbers to compare. The greatest common factor is the largest factor that all the numbers have in common - the largest factor that they all share.


What are the common factors and greatest common factor of 125?

There cannot be a greatest common factor if there are not at least two numbers to compare. The greatest common factor is the largest factor that all the numbers have in common - the largest factor that they all share.


Is the greatest common factor how many of each type?

No. The Greatest Common Factor (GCF) is the greatest factor that is in common with the numbers you are given.


What one number has the greatest common factor of 871?

Answer: None, it is impossible. No single number has a greatest common factor. A "common factor" is a factor that two or more numbers have in common. The "greatest common factor" is the largest factor that two or more numbers have in common.


Does 37 have a greatest common factor?

No. There is not a greatest common factor of a single number, such as 37, because there cannot be a greatest common factor without two or more numbers to compare. Common factors are factors that the numbers being compared have in common. The greatest common factor is the largest factor that all the numbers being compared have in common.