# Help with some logic questions

Printable View

• 01-13-2003
TheLoneWolf32
Help with some logic questions
Okay I am a basic C++ student in high school...I am to write a function on getting a GCF from 2 integers...I am first thinking of the logic of the problem first and how to solve it...So far I've come up with one idea, I am not so sure it is good but its what my mind has come up with...Please either tell me that its a bad method on trying to do this and if it is a bad method, what is a better one?

Okay I am going to find the prime factors of each numbers. Then I will multiply the common numbers together to get the GCF...all idea's are welcome

Also for another program I am working on, is zero considered an even number?(I'm writing another function to remove all even numbers from an array and I am wondering if zero is included as an even number)
• 01-13-2003
Munkey01
I don't remember enough about GCM, GCF, LCM, LCF to tell you the answers to the first. But for 0 being an even number I would have to say yes. Because

Code:

`(0 % 2 == 0)`
is a true statement.
• 01-13-2003
Sang-drax
Yes, 0 is an even number
http://mathworld.wolfram.com/EvenNumber.html
Quote:

An integer of the form n=2k , where n is an integer. The even numbers are therefore ..., -4, -2, 0, 2, 4, 6, 8, 10, ... (Sloane's A005843).
• 01-14-2003
Nick
You can write a quick, not to mention easier to code, nonrecursive algorithm with these facts
gcd(a, 0) = a
Since a divides a and 0

gcd(a, b) = gcd(b, a % b)
Suppose there is a g that divides a and b. Does that
g divide a % b? Yes, simply let r = a % b and you
have a = bq + r where q and r are integers such that 0 <= r < q.

This algorithm is called Euclid's algorithm and it's supposed to be
the oldest non-trivial algorithm.