# Use the Euclidean theorem to obtain the maximum common number and the least common number.

Source: Internet
Author: User

Use the Euclidean theorem to obtain the maximum common number and the least common number.

`function gcd(a,b){return b == 0 ? a : gcd(b,a%b);}function lcm(a,b){return a * b / gcd(a,b);}console.log(gcd(24,42));console.log(lcm(16,36));`

Description of the maximum common divisor and least common multiple of two numbers programmed in C language: the maximum of the two positive integers using the moving phase division (that is, the Euclidean Algorithm)

# Include <stdio. h>
Void main ()
{
Int a, B, c, d, div, rem; // a, B is the input number
Scanf ("% d", & a, & B );
If (a <B)
{
C =;
A = B;
B = c;
}
D = a * B; // The product of input numbers a and B
Div = B;
While (a % div! = 0)
{
C = a % B;
A = div;
Div = c;
}

Rem = d/div;

Printf ("% d \ n", rem );
}

In C language, use the function to call the maximum public approx. And the minimum public multiple

# Include <stdio. h>
Int main ()
{

Int m, n;

Int f (int m, int n );

Printf ("please input two numbles :");

Scanf ("% d", & m, & n); // note the input format. You have added ','.

Printf ("the max is % d \ n", f (m, n ));

Printf ("the min is % d \ n", m * n/f (m, n ));

Return 0;
}

Int f (int m, int n)
{
Int c;

C = m % n;

While (c! = 0)
{

M = n;

N = c;

C = m % n;

}

Return (n );
} // Learn to debug simple programs

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.