All things are lawful, but not all things are profitable.
Knute Snortum wrote:I As you've described it, I don't see how k could be 1.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Eddie Gerlach wrote:now I can see logically where k (2 in this example) is not <= n1/2, which is 3/2 or 1, since we're dealing w/integers, yet when I compile and run, my answer is indeed, gcd = 1.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Eddie Gerlach wrote:Gosh, I'm a boob....the gcd of 3 and 3 is 3, not 1! Went back and examined my code.....when I enter the '/2' divisor in the 'for' loop and re-evaluate, it's an incorrect process to determine the "%" remainder, yes? swimming, swimming, swimming.....
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:2) in your second code, line 02, I see:...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Emil Jennings wrote:@Winston I was addressing issues in the original post.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Eddie Gerlach wrote:Winston,
Thanks for catching that...I was simply reading from my textbook and I could've entered the code incorrectly....
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
'while' these two conditions exist, AND if (n1 % k == 0 && n2 % k == 0), then 'k' is incremented by 1...since it started at 2, shouldn't it then be incremented by 1 and then gcd is 3?
since this is a Boolean statement that requires the first statement to evaluate as true, and if it doesn't, it ignores the 2nd condition?
Then the loop starts anew until a new value is stored for gcd (or 'k') or k becomes >= n1 or n2?
Sorry, but noobie brainfarts and perhaps a bit "loop"y...
Eddie Gerlach wrote:From what I can gather, 'while' these two conditions exist, AND if (n1 % k == 0 && n2 % k == 0), then 'k' is incremented by 1...since it started at 2, shouldn't it then be incremented by 1 and then gcd is 3? However, since this is a Boolean statement that requires the first statement to evaluate as true, and if it doesn't, it ignores the 2nd condition? Then the loop starts anew until a new value is stored for gcd (or 'k') or k becomes >= n1 or n2?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |