Sunday, October 23, 2011

GCD and LCM

#include< stido.h>
#include< conio.h>
void main( )
{
    int a,b,gcd,lcm;
    clrscr( );
    printf("Enter the two integer values:");
    scanf("%d%d", &a, &b);
    lcm=a*b;
    while(a!=b)
    {
        if(a>b)
        a=a-b;
        else
        b=b-a;
    }
    gcd=a;
    lcm=lcm/gcd;
    printf("\n The GCD is : %d",gcd);
    printf("\n The LCM is : %d",lcm);
    getch( );
}

No comments:

Post a Comment