WAP to find GCD of two number using function.


#include<iostream>
#include<conio.h>

using namespace std;

int gcd(int x,int y);

int main()
{
int a,b;
cout<<"Enter two number : ";cin>>a>>b;
cout<<"\nThe GCD of "<<a<<" and "<<b<<" is "<<gcd(a,b);
getch();
return(0);
}

int gcd(int x,int y)
{
int z=x%y;
if(z==0)
return(y);
else
return(gcd(y,z));
}

No comments:

Post a Comment