#include<stdio.h>
int lcm_find(int n,int m, int temp)
{
if(temp%n==0 && temp%m==0) ///base case
{
return temp;
}
else
{
return lcm_find(n,m,temp+1); ///recursion
}
}
int main()
{
int n,m,i,temp;
printf("Please Enter 1st Number: ");
scanf("%d",&n);
printf("Please Enter 2nd Number: ");
scanf("%d",&m);
///finding the biggest number
if(n>=m)
{
temp=n;
}
else
{
temp=m;
}
int LCM =lcm_find(n,m,temp);
printf("
The LCM of %d and %d is: %d
",n,m,LCM);
return 0;
}
Output
Please Enter 1st Number: 10
Please Enter 2nd Number: 15
The LCM of 10 and 15 is: 30
Add your comment