//Given two numbers, this program finds the greatest common divisor
#include<iostream.h>
template <class T>
void swap(T &,T &);
int gcd(int a, int b);
int main()
{
int a,b;
cout<<"Enter first number :";cin>>a;
cout<<"Enter second number :";cin>>b;
cout<<"GCD =  "<<gcd(a,b)<<endl;
return 0;
}

int gcd(int a, int b)
{
int t;
if (a<b) swap(a,b);
while(a%b)
{
t=b;
b=a%b;
a=t;
}
return b;
}

template <class T>
void swap(T &a,T &b)
{
T t;//t is a temprroary buffer
t=a;
a=b;
b=t;
}