Tuesday 8 October 2013

gcd using c++


#include<iostream.h>
int gcd(int x,int y)
{
if(x==y)
return (x);
else
{
if(x>y)
gcd(x-y,y);
else
gcd(x,y-x);
}
}
void main()
{
int n1,n2,g;
cin>>n1>>n2;
g=gcd(n1,n2);
cout<<"gcd of "<<n1<<" & "<<n2<<" is :"<<g;
}

No comments:

Post a Comment