input any two positive integers how to seek their Least Common Multiple and Greatest Common Divisor in c.
thank.
#include
void main(void)
{
int x,y;
printf("input any two positive integers:");
scanf("%d %d",&x,&y);
/*
...
*/
}


VulpesRank #55 · 29.2K reputationPosted Jul 22, 2013, 4:28 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 20, 2013, 7:47 PM EDT
#include #include int gcd( int m, int n) { while( m!= n) // execute loop until m == n { if( m > n) m= m - n; // large - small , store the results in large variable else n= n - m; } return ( m); // m or n is GCD } int lcm( int m, int n) { int gcd( int, int); return( m * n / gcd (m , n)); // product of 2 numbers / gcd is lcm } main() { int m, n , lcm( int, int), gcd( int ,int); printf(" enter anyu 2 values \n"); scanf("%d%d", &m,&n); printf(" gcd is %d\n", gcd( m, n)); printf(" lcm is %d\n", lcm(m , n)); getch(); }Ken HRank #2,315 · 610 reputationPosted Jul 21, 2013, 5:10 PM EDT
thank for answer.
If the number is three or more numbers, than if there is a better solution? :)
Ken HRank #2,315 · 610 reputationPosted Jul 22, 2013, 11:27 PM EDT
thank for your answer.
Regards,
Ken :)