Advertisement
afrinahoque

GCD and LCM of two numbers

Jun 21st, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include<stdio.h>
  2. int main ()
  3. {
  4.     int num1,num2,n1,n2,rem,GCD,LCM;
  5.     printf("Enter the numbers:");
  6.     scanf("%d%d", &num1, &num2);
  7.     n1=num1;
  8.     n2=num2;
  9.     while (n2!=0)
  10.     {
  11.         rem=n1%n2;
  12.         n1=n2;
  13.         n2=rem;
  14.     }
  15.     GCD=n1;
  16.     printf("GCD=%d\n", GCD);
  17.     LCM=(num1*num2)/GCD;
  18.     printf("LCM=%d\n", LCM);
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement