Finding GCD and LCM of Given Numbers using C

 Finding GCD and LCM

include

int main()
{
    int no1, no2, rem=0, n1,n2;
    printf(“Enter Two Non-Zero Integer Mumbers:”);
    scanf(“%d%d”,&no1,&no2);
    n1=no1;
    n2=no2;
    rem=no1%no2;
    while(rem != 0)
    {
        no1=no2;
        no2=rem;
        rem=no1%no2;
    }
    printf(“\n GCD of %d and %d is %d”, n1,n2,no2);
    printf(“\n LCM of %d and %d is %d”,n1,n2,(n1*n2)/no2);
    return 0;
}

OUTPUT:

Enter Two Non-Zero Integer Mumbers:15 25
GCD of 15 and 25 is 5
LCM of 15 and 25 is 75

Leave a Reply

Your email address will not be published.