C Program to Find HCF and LCM of Two Numbers

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int  x, y,m,n, hcf, lcm;
    printf("\n Enter two number : ");
    scanf("%d%d",&x, &y);
    m=x;
    n=y;
    while(m!=n)
    {
        if(m>n)
        m=m-n;
        else
        n=n-m;
    }
    hcf=m;
    lcm=(x*y)/hcf;
    printf("\n HCF of %d and %d is %d",x,y,hcf);
    printf("\n LCM of %d and %d is %d",x,y,lcm);
    getch();
}

Run1:
Run2:


1 comment:

  1. Thank u sir.
    I am searching this program in many website.
    But no clear.
    Now your concept is easy.

    ReplyDelete

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...