LCM of 2 number

Program Description

In this code a the lcm of given 2 number is calculated.
For this we have started looping from 1 to a*b where a and b are two number.
For eg. Given number is 2 and 3 then output will be 6.

Program
/***********************************
*   LCM of 2 number
*	
*	code.cheraus.com
*
***********************************/
#include<stdio.h>
#include<conio.h>

void main()
{
  int a,b,i;
  clrscr();
  printf("\nEnter the two numbers : ");
  scanf("%d%d",&a,&b);
  
  for(i=1;i<=a*b;i++)
   {
      if((i%a==0) && (i%b==0))
	  {
	    printf("\nLCM of %d and %d is : %d",a,b,i);
		break;
	  }
   }
   getch();
}

Output
Test Case 1:

Enter the two numbers : 10 20
LCM of 10 and 20 is : 20

Test Case 2:

Enter the two numbers : 15 20
LCM of 15 and 20 is : 60

Comments
comments powered by Disqus