Find HCF and LCM of Two Numbers in C

Find HCF and LCM of Two Numbers in C

To find the HCF and LCF of two number in C programing, you have to ask to the user to enter the two numbers, to find the HCF and LCF of the two number to display the value of the HCF and LCM of the two numbers.

C Programming Code to Find HCF and LCM of Two Numbers

Following C program ask to the user to enter any two number to find HCF & LCM, then display the result on the screen :
/* C Program - Find HCF and LCM of Two Numbers */
#include<stdio.h>
#include<conio.h>
int main()
{
 int a, b, x, y, t, hcf, lcm;
 printf("Enter two number : ");
 scanf("%d%d",&x, &y);
 a=x;
 b=y;
 while(b!=0)
 {
  t=b;
  b=a%b;
  a=t;
 }
 hcf=a;
 lcm=(x*y)/hcf;
 printf("HCF = %d\n",hcf);
 printf("LCM = %d",lcm);
 return 0;
}
When the above c program is compile and executed, it will produce the following result:

No comments:

Post a Comment

Featured post

Introduction to my blog

INTRODUCTION  TO  MY  BLOG Hello , That was my first blog so I did not know how to start writing my first blog post. So here goes ,...