0 votes
967 views
in C programming by (98.9k points)
edited
C Program to Find Hcf and Lcm of Two Numbers

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer
#include <stdio.h>
#include <conio.h>
 
int main() {
  int a, b, num1, num2, temp, gcd, lcm;
  
  printf("Enter two numbers\n");
  scanf("%d %d", &a, &b);
 
  num1 = a;
  num2 = b;
  
  while (num2 != 0) {
    temp = num2;
    num2 = num1 % num2;
    num1 = temp;
  }
  
  gcd = num1;
 
  lcm = (a*b) / gcd;
  
  printf("GCD of %d and %d is %d\n", a, b, gcd);
  printf("LCM of %d and %d is %d\n", a, b, lcm);
   
  getch();
  return 0;
}

 

Related questions

0 votes
1 answer 219 views
0 votes
1 answer 308 views
0 votes
1 answer 327 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

554 users

...