WAP TO PRINT GCD USING RECURSION - Algorithm Design and Analysis Lab file

WAP TO PRINT GCD USING RECURSION

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int gcd(int x,int y)
{
            int r;
            r=x%y;
            if(r==0)
            {
                        return y;
            }
            else
            {
                        gcd(y,r);
            }
}

void main()
{
clrscr();
int x,y,g;
cout<<"enter nos.::";
cin>>x>>y;
if(x>y)
{g=gcd(x,y);}
else
{g=gcd(y,x);}
cout<<"\ngreatest commen divisor is::"<<g;
getch();
}

OUTPUT:


No comments:

Post a Comment