Euclid method for solving GCD problem
Hello,
I am trying to use the Euclidean method for solving the GCD problem. However, I keep getting an infinite loop. After I input num1 and num2, the program doesn't respond with anything and doesn't allow me to type anything either. Here is the code:
Code:
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
main()
{
int num1, num2, rem, x, y;
printf ("This program calculates the GCD of two numbers.\n");
printf ("Enter the first number: ");
num1 = GetInteger();
printf ("Enter the second number: ");
num2 = GetInteger();
x = num1;
y = num2;
rem=(num1%num2);
while (rem != 0)
{
rem == num1 % num2;
if (rem == 0)
{
printf ("The GCD of %d and %d is %d", x, y, num2);
}
else
{
num1 == num2;
num2 == rem;
}
}
getchar();
}