Write a Program to find GCD of two numbers

Source Code:

#include <bits/stdc++.h>
int GCD(int,int); ///Function Prototype

int main()
{
      int a,b,result;
      while(scanf(“%d %d”,&a,&b)==2)
      {
          result=GCD(a,b); ///Function Calling
          printf(“GCD of %d and %d is: %d\n”,a,b,result);
      }
return 0;
}
int GCD(int p,int q) ///Function/Recursion Definition
{
     if(q==0)
       return p;
    else if(p>q)
      return GCD(q,p);
   else
     return GCD(p,q%p);

return -1;
}

Share

One thought on “Write a Program to find GCD of two numbers

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Lean Blog by Crimson Themes.