Question
The ancient Greek mathematician Euclid developed a method forfinding the greatest common divisor of two integers, a andb. His method is as follows:
- If the remainder of a/b is 0 then b is thegreatest common divisor.
- If it is not 0, then find the remainder r ofa/b and assign b to a and the remainderr to b.
- Return to step (A) and repeat the process.
Write a program called gcd.c that takes a andb as inputs from the user and uses a function to performEuclid's procedure. Display a and b and thegreatest common divisor
Explanation / Answer
please rate - thanks # include #include int gcd(int,int); int main() { int num1; int num2; printf("Enter the first number "); scanf("%d", &num1); printf("Enter the first number? "); scanf("%d", &num2); printf(" The GCD %d ",gcd(num1,num2 )); getch(); //use this, needs conio to be included return 0; } int gcd(int a, int b) //Euclidsalgorithm {int r; if(b==0) r=a; else {r=a%b; while(r!=0) {a=b; b=r; r=a%b; } } return b; }