Thursday, 20 March 2014

Write a C program to find the HCF and LCM of two numbers.

#include<stdio.h>

main()
{
    int a,b,temp,i;
    printf("\nEnter two numbers=");
    scanf("%d%d",&a,&b);
    if(a>b)
    {
        temp=a;
        a=b;
        b=temp;
    }
   
    for(i=a;i>=1;i--)
    {
        if(a%i==0 && b%i==0)
        {
            break;
        }
    }
    printf("\nHCF=%d",i);
    printf("\nLCM=%d",a*b/i);
}

No comments:

Post a Comment