Advertisement
Fahim_789

Lcd and Gcd

May 27th, 2019
243
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 two numbers : ");
  6.     scanf("%d %d",&num1,&num2);
  7.  
  8.     n1=num1;
  9.     n2=num2;
  10.  
  11.     while(n2!=0)
  12.     {
  13.         rem=n1%n2;
  14.         n1=n2;
  15.         n2=rem;
  16.     }
  17.     gcd=n1;
  18.     lcm=(num1*num2)/gcd;
  19.     printf("gcd=%d\n",gcd);
  20.     printf("lcm=%d\n",lcm);
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement