The maximum public factor, also known as the maximum public approx. It refers to the maximum public factor of [n (limit 2) Natural numbers a1, a2,...,. There are usually two representation methods: the largest of all their public factors; if the natural number m is the public factor of the n natural numbers, and any public factor of the n numbers is the factor of m, m is the maximum use factor of n.
The maximum public factor, also known as the maximum public approx. It refers to the maximum public factor of [n (limit 2) Natural numbers a1, a2,...,. There are usually two representation methods:
- The largest of all their public factors;
- If the natural number m is the public factor of the n natural numbers and any public factor of the n numbers is the m factor, m is the maximum factor used for the n numbers. The description in China is generally [(a1, a2 ,..., [g. c.d. (a1, a2 ,..., an)].
Euclidean Algorithm (Euclidean Algorithm) (Euclid's Algorithm) is generally referred to as the division of the moving phase for finding the maximum public factor. The algorithm is described as follows:
- If a is divided by B, the maximum number of common divisor is B;
- Otherwise, the maximum number of common dikes is equal to the number of common dikes of B and a % B.
The code is implemented as follows:
#include
int Euclidean(int parA, int parB){ if (parB == 0) { return parA; } else { return Euclidean(parB, parA % parB); }}int main(void){ int intA, intB; printf("Enter two number to calculate its GCD:\n"); scanf("%d %d", &intA, &intB); printf("The GCD of %d and %d is %d\n", intA, intB, Euclidean(intA, intB)); return 0;}
Or
#include
int Euclidean(int parA, int parB){ return (!parB)?parA : Euclidean(parB, parA % parB);}int main(void){ int intA, intB; printf("Enter two number to calculate its GCD:\n"); scanf("%d %d", &intA, &intB); printf("The GCD of %d and %d is %d\n", intA, intB, Euclidean(intA, intB)); return 0;}
Address of this article: http://www.nowamagic.net/librarys/veda/detail/451,welcome.