Header Ads

LCM OF TWO NUMBERS IN C

LCM OF TWO NUMBERS:The least common multiple, or LCM, is another number that's useful in solving many math problems. Let's find the LCM of 30 and 45. One way to find the least common multiple of two numbers is to first list the prime factors of each number.
30 = 2 × 3 × 5 45 = 3 × 3 × 5
Then multiply each factor the greatest number of times it occurs in either number. If the same factor occurs more than once in both numbers, you multiply the factor the greatest number of times it occurs.
Then multiply each factor the greatest number of times it occurs in either number. If the same factor occurs more than once in both numbers, you multiply the factor the greatest number of times it occurs.
2: one occurrence  3: two occurrences  5: one occurrence  2 × 3 × 3 × 5 = 90 <— LCM
After you've calculated a least common multiple, always check to be sure your answer can be divided evenly by both numbers.
PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
 int num1,num2,a,i=1;
 printf("\nEnter the num1:");
 scanf("%d",&num1);
 printf("\nEnter the num2:");
 scanf("%d",&num2);
 while(i<=num1)
 {
  a=num2*i;
  if(a%num1==0)
  {
  printf("\nThe LCM is %d",a);
  break;
  }
  i=i+1;
 }
 getch();
}
OUTPUT:
SCREEN SHOT OF LCM PROGRAM


No comments