Showing posts with label GCD. Show all posts
Showing posts with label GCD. Show all posts

Tuesday, June 16, 2020

GCD Using Recursion in C++


    #include<iostream>
    using namespace std;
    void rec(int a,int b, int l){
      if(a % l == 0 && b % l == 0){  
        cout<<"G.C.D of "<<a<<" and "<<b<<" = "<<l;
      return;
      }
      rec(a,b,--l);  
    }

    int main(){
      int x,y,s;
      cin>>x>>y;
      if(x<y)
        s = x;
      else
        s = y;
      rec(x,y,s);
    }

horizontal ads