Monday, July 8, 2019

LCM and HCF of the two numbers in c programming

#include <stdio.h>
#include <stdlib.h>


int m, n;
main( )
{
    int x,y;
    printf ("Enter two numbers ");
    scanf ("%d %d·" , &x, &y);
    printf ("RCF of %d and %d is %d\n", x, y, hcf (x, y) );
    m=x;n=y;
    printf ("LCM of %d and %d is %d\n", x, y, lcm (x, y) );
}
int hcf(int a, int b)
{
    if(a==b)
        return(b);
    else if (a<b)
        hcf(a,b-a);
    else
        hcf(a-b,b);
}
int lcm(int a, int b)
{
    if (a==b)
        return(b);
    else if(a<b)
        lcm(a+m,b);
    else
        lcm(a,b+n);
}


output:

Enter two numbers 12
15
RCF of 12 and 15 is 3
LCM of 12 and 15 is 60

No comments:

Post a Comment

python class topic video