Seeking the maximum number of conventions and the least common

xiaoxiao2021-03-06  45

#include

//// largest COMMON DIVISOR // Rossing Different: // Use m, n, r to represent the divisor, divisor, and remainder. The remainder R is obtained. // 2 If r = 0, then n is the maximum number of conventions. If r ≠ 0, execute the starting step. / 3 Place the N value in M, put the value of R in n.// 4 return Re-execute step 1. // unsigned long M, unsigned long n) {unsigned long Temp;

While (n) {temp = n; n = m% n; m = TEMP;} return m;

// // There is also a recursive algorithm: // if (m == 0) // {// Return N; //} // Return GCD (N% M, M); //}

/// / minimum male // unsigned long lcm (unsigned long M, unsigned long n) {RETURN M / GCD (M, N) * n;

// // The other method is: // unsigned long a; // for (a = 1; a <= m * n; A ) // {// IF ((a% m == 0) && A% n == 0)) // {// Break; // This ended here, found the least common multiple. //} //} // Return a; ///}

Void main () {Unsigned long M, N, A;

Printf ("Enter two numbers (separated by space):"); scanf ("% lu% lu", & m, & n); if ((m <0) || (n <0)) {return;}

A = LCM (M, N); Printf ("% lu and% lu's least m, N, A);

A = GCD (M, N); Printf ("% lu and% lu is% lu / N", M, N, A);

}

转载请注明原文地址:https://www.9cbs.com/read-55813.html

New Post(0)