Least common multiple and greatest common divisor of two numbers

// tossing and dividing

        #include<stdio.h>  

int main()  
{  
    int x, y, z, m, n;  
    printf("Please enter two numbers: ");  
    scanf("%d%d", &x, &y);  
    m = x, n = y;  
    while (y != 0)  
    {  
        z = x%y;  
        x = y;  
        y = z;  
    }  
    printf("The greatest common divisor is: %d\n", x);  
    printf("The least common multiple is: %d\ n", m*n / x);  
    return 0;  

}  

tossing and turning

#include<stdio.h> //Subtract
int main()  
{  
int x, y, m, n;  
printf("Please enter two numbers: ");  
scanf("%d%d", &x, &y );  
m = x, n = y;  
while (x!=y)  
{  
    if (x>y)  
        x = xy;  
       else  
        y = yx;  
}  
    printf("The greatest common divisor is: %d\n", x) ;  
    printf("The LCM is: %d\n", m*n / x);    
    return 0;  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324689151&siteId=291194637