Switch to full style
For C/C++ coders discussions and solutions
Post a reply

Greatest common divisor

Sun May 25, 2008 3:48 pm

Greatest common divisor in c++ using recursion method :gOOd:

cpp code
#include<iostream>
using namespace std;
int GCD(int ,int );
void main()
{
int x,y;
cout<<"Plz enter the two numbers : ";
cin>>x>>y;
cout<<"The GCD("<<x<<","<<y<<") = " << GCD(x,y)<<endl;
}
int GCD(int x,int y)
{
if(y>x)return GCD(y,x);
if(x==y)return x;
if(x%y==0)return y;
return GCD(x,x-y);

}




Post a reply
  Related Posts  to : Greatest common divisor
 greatest common divisor (GCD)     -  
 greatest common divisor-code-c     -  
 Greatest Comman Divisor using Java     -  
 Error 500: java.lang.NoClassDefFoundError: org.apache.common     -  

Topic Tags

C++ Algorithms