Seeking two positive integers?

xiaoxiao2021-04-03  234

Given two positive integers, ask for the maximum number of conventions, for this algorithm, I must know that the most classic way to solve this problem is to use the Ou Sri German algorithm, which is said to be the earliest algorithm in history.

#include

#include

#define

MAX (A, B) (a)> (b)? (a): (b)

#define

MIN (A, B) (a) <(b)? (a): (b)

/ *

INPUT: M, N (m> 0, n> 0)

Output: -1 Error, else the commit divisor of m and n

* /

int

G * c * d (int M, int N)

{

INT A = max (m, n);

INT b = min (m, n);

Int remainder = 1;

IF (m <= 0 || n <= 0)

{

Return -1;

}

While (remainder> 0)

{

Remainder = a% B;

A = B;

B = remainder;

}

Return A;

}

int

Main (int Argc, char * argv [])

{

Int first, second, result

IF (argc! = 3)

{

FPRINTF (stderr, "there" there ");

EXIT (-1);

}

First = ATOI (Argv [1]);

Second = ATOI (Argv [2]);

Result = g * c * d (first, second);

IF (Result! = -1)

{

Printf ("THE COMMON DIVISOR OF% D and% D IS% D / N", First, Second, Result;

}

Else

{

Printf ("M and N Should Be Greater Than 0 / N");

}

Return 0;

}

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

New Post(0)