Monday, 6 July 2015

Write C Program To Find LCM and HCF

1:  #include <stdio.h>  
2:  int main() {  
3:   int a, b, x, y, t, gcd, lcm;  
4:   printf("Enter two integers\n");  
5:   scanf("%d%d", &x, &y);  
6:   a = x;  
7:   b = y;  
8:   while (b != 0) {  
9:    t = b;  
10:    b = a % b;  
11:    a = t;  
12:   }  
13:   gcd = a;  
14:   lcm = (x*y)/gcd;  
15:   printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);  
16:   printf("Least common multiple of %d and %d = %d\n", x, y, lcm);  
17:   return 0;  
18:  }  

No comments:

Post a Comment