About us

C Program for finding the GCD of two numbers using Recursion


C Program for finding the GCD of two numbers using Recursion


c-program-finding-GCD-two-numbers-using-recursion



#include<stdio.h>
#include<conio.h>
int hcf(int a,int b);

void main()
{
 int x,y;
 clrscr();
 printf("Enter Any Two numbers for Find their GCD\n");

 scanf("%d %d",&x,&y);
 printf("\nThe GCD is %d",hcf(x,y));
 getche();
}

int hcf(int a,int b)
{
 if(a==b)
  return a;
 else if(a>b)
  if(a%b==0)
   return b;
  else
   hcf(a%b,b);
 else
  if(b%a==0)
   return a;
  else
   hcf(a,b%a); 
}


OUTPUT



c-program-finding-GCD-two-numbers-using-recursion




------------------------------------------------------------------------------------------------------------

You can also visit:-