-
problem on c programming
I have a problem determining the greatest common divisor of any two numbers. The question goes as follows;
The greatest common divisor (GCD) of two integers is the largest integer that evenly divides each of the two numbers. Write a function gcd the "gcd" that returns the greatest common divisor of two integers.
This question is taken from INTRODUCING C++ AND JAVA /HOW TO PROGRAM C ( THIRD EDITION ) AUTHOR: DEITEL & DEITEL
PLEASE I WILL BE GRATEFUL IF THIS PROBLEM IS SOLVED AND REPLIED TO ME QUICKLY.
THANKS
MIKE
-
int GCD(int a,int b)
{
int c;
a=a>0?a:-a;
b=b>0?b:-b;
if(a<b){
c=a;
a=b;
b=c;
}
if(!b)return(a);
while(c=a%b){
a=b;
b=c;
}
return(b);
}
BTW: i haven't tested it.