C Program to find LCM and HCF Of Two Number Using Recursion - 3

How to write a C Program to find LCM and HCF Of Two Number Using Recursion in C Programming Language ?


Solution For C Program :

/*C Program to find LCM and HCF Of Two Number Using Recursion.*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,old_rem,cur_rem,lcm,hcf;
int hccf(int, int);
clrscr();
printf("Enter the two no:");
scanf("%d%d",&a,&b);
if(a<b)
  {
  old_rem=b;
  cur_rem=a;
  }
  else
  {
  old_rem=a;
  cur_rem=b;
  }
hcf=hccf(old_rem,cur_rem);
lcm=(a*b)/hcf;
printf("LCM=%d\tHCF=%d",lcm,hcf);
getch();
}

hccf(int old_rem,int cur_rem)
    {
    int new_rem,hcf;
    new_rem=old_rem%cur_rem;
    old_rem=cur_rem;
    cur_rem=new_rem;
    if(new_rem==0)
      {
      return(old_rem);
      }
    else
      {
      hcf=hccf(old_rem,cur_rem);
      }
      return(hcf);
    }


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable


Learn More :