Let’s step it through:
f(12, 18) -> a = 12, b = 18
int a1 = a, b1 = b; -> a1 = 12, b1 = 18
while (a1 != b1) -> not equal -> do the loop
if (a1 < b1) a1 += a; -> a1 = 24
while (a1 != b1) -> not equal -> do the loop
if (a1 < b1) ... else b1 += b; -> b1 = 36
while (a1 != b1) -> not equal -> do the loop
if (a1 < b1) a1 += a; -> a1 = 36
while (a1 != b1) -> equal -> end the loop
return a1 -> return 36
2
solved Why the output is 36 and not 24?