I have created the following program:
#include <iostream>
int main(){
int a,b,mod, a1,b1;
std::cin >> a >> b;
if(a >= b){
mod = a % b;
} else {
mod = b % a;
}
if(mod == 0){
std::cout << a;
} else {
while(a1 != 0 && b1 != 0){
a1 = a % mod;
b1 = b % mod;
--mod;
}
std::cout << mod + 1;
}
return 0;
}
I have tested with the following input: 25 27 and got result 1 (as expected).
But in another compiler I got result 3 and unfortunately I don’t have an access to testing with another compiler(only the final result). I don’t know why and where the behaviour of my program is inconsistent.
>Solution :
a1 and b1 is not initialized by correct numbers. If you set correct initial version, you should get consistent behavior.