GCD using the euclid method.
I have an assignment to use the euclid method to solve the GCD of two integers. Here is what I have so far:
Code:
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
main()
{
int num1, num2, rem, GCD;
printf ("This program calculates the GCD of two numbers.\n\n");
printf ("Enter the first number: ");
num1 = GetInteger();
printf ("Enter the second number: ");
num2 = GetInteger();
while (rem != 0)
{
if (rem == 0)
{
GCD = num2;
printf ("The GCD of %d and %d is %d", num1, num2, num2);
}
if (rem != 0)
{
num1 = num2;
num2 = rem;
}
}
getchar();
}
When I compile it, the program never gives me a solution, which means it's running an infinite loop and I can't figure out how to stop it.