Wednesday, 3 October 2018

LCM of two numbers

#include<stdio.h>
int lcm(int,int);
void main()
{
      int a,b,result;
      printf("\nEnter two numbers");
      scanf("%d%d",&a,&b);
      result=lcm(a,b);
      printf("\nLCM=%d",result);
}
int lcm(int a,int b)
{
     static int common=1;
     if(common%a==0&&common%b==0)
          return common;
     common++;
     lcm(a,b);
}

No comments:

Post a Comment