Sorry for my confusion, ya'll....went out for a run to clear my head...I think it may have helped....
the original code used a while loop:
int gcd = 1; // initial gcd is 1
int k = 2; //possible gcd
while (k <= n1 %% k <= n2) {
if ( n1 % 2 == 0 && n2 % 2 == 0)
gcd = k;
k++;
}
I then replaced it with a for loop:
int gcd =1; //initial gcd is 1
for (int k = 2; k <= n1 && k <= k2; k++) {
if (n1 % k == 0 && n2 % k == 0)
gcd = k;
}
Finally, when asked to insert the "/2" into the loop-continuation-condition, I was instructed that this is wrong and was asked why..(in the book)
for (int k =2; k <= n1 / 2 && k <= n2 / 2 ; k++) {
if (n1 % k == 0 && n1 % k == 0)
gcd = k;
For all 3 conditions, when I used the example 125 and 2525, gcd = 25...so this obviously left me wondering why the 3rd set of code was incorrect...however, when I enter 3 and 3 for the 3rd set of code, gcd is 1....it should be 3, correct? Same goes for 2 and 2..gcd should be 2, not 1...Hence my inquiry here...
BTW, Emil, when I take your parameters (n1 = 16 and n2 = 24) into the 3rd set of code, my answer is indeed 8...so there is my nightmare, folks.... isn't this fun?!
Appreciate the assistance everyone.
.....swimming, swimming, swimming.....