FIND THE LCM USING RECURSION - C-Tutorial

Latest

Monday, 26 September 2016

FIND THE LCM USING RECURSION

/* TO FIND THE LCM USING RECURSION */


#include<stdio.h>
#include<conio.h>
int lcm(int,int);
main()
{
int a,b,l;
clrscr();
printf("\n Enter a,b values: ");
scanf("%d%d",&a,&b);
l=lcm(a,b);
printf("\n LCM of %d and %d is = %d",a,b,l);
getch();
}

int lcm(int a,int b)
{
static int c=1;

if((c%a==0)&&(c%b==0))
return c;
else
c++;
lcm(a,b);
}

No comments:

Post a Comment