Solving the greatest common divisor using C++ and the Euclid method
Below is my code:
#include "stdafx.h"
#include "genlib.h"
#include "simpio.h"
#include "math.h"
int _tmain(int argc, _TCHAR* argv[])
{
int num1,num2,rem;
printf("Enter 1st number: ");
num1=GetInteger();
printf("Enter 2nd number: ");
num2=GetInteger();
rem=num1%num2;
;if(rem==0)
{
printf("The GCD of %d and %d is %d\n",num1,num2,num2);
}
else
{num1=num2;
num2=rem;
while (1==1)
{
if (rem==0)
{
printf("The GCD of %d and %d is %d\n",num1,num2,num2);
}
else
{
num1=num2;
num2=rem;
}
}
}
}
Please tell me what I did wrong, because the above code doesn't work for all numbers.
thank you