a). using Recursive function
int gcd (int, int); //func. declaration.
void main( )
{
int a, b, res;
clrscr( );
cout<<"Enter the two integer values:";
cin>> a >>b;
res= gcd(a, b); // calling function.
cout<<" GCD is:" << res;
getch( );
}
int gcd( int x, int y) //called function.
{
int z;
z=x%y;
if(z==0)
return y;
gcd(y,z); //recursive function
}
Note:- If u have any doubt regarding this program or logic, please feel free to contact me.
Wednesday, February 25, 2009
Subscribe to:
Post Comments (Atom)
thanks you have really assisted me
ReplyDelete