Programmer interview question selection (47): solutions to the maximum and minimum public multiples of two or N numbers

Source: Internet
Author: User

The code is implemented as follows:

# Include <iostream>

Using namespace STD;

Int getg (int m, int N)
{
If (M <n)
{
M ^ = N;
N ^ = m;
M ^ = N;
}
If (n = 0)
Return m;
Return getg (n, m % N );
}

Int getng (int * arr, int N)
{
// Int IMAX = arr [0];
// For (INT I = 1; I <n; I ++)
// IMAX = getzuidagongyue (IMAX, arr [I]);
// Return IMAX;
If (n = 1)
Return * arr;
Return getg (ARR [n-1], getng (ARR, n-1 ));
}

/* Int getg (int * arr, int Len)
{
Int IMAX = arr [0], icurr, iremainder;
 
For (INT I = 1; I <Len; I ++)
{
Icurr = arr [I];

If (IMAX <icurr)
{
IMAX ^ = icurr;
Icurr ^ = IMAX;
IMAX ^ = icurr;
}

Iremainder = IMAX % icurr;

While (iremainder)
{
IMAX = icurr;
Icurr = iremainder;
Iremainder = IMAX % icurr;
}

IMAX = icurr;
} //
 
Return IMAX;
 
}
*/

Int getlcm (int m, int N)
{
Return M * n/getg (m, n );
}

Int getnlcm (int * arr, int Len)
{
If (LEN = 1)
Return * arr;
Return getlcm (ARR [len-1], getnlcm (ARR, len-1 ));
}

Int main ()
{
Cout <"----------------- g -------------------" <Endl;
Cout <"5767 and 4453:" <getg (5767,4453) <Endl;
Int arr [6] = {, 40 };
Cout <", 40, 30 and 80:" <getng (ARR, 6) <Endl;
Cout <"----------------- LCM -------------------" <Endl;
Cout <", 40, 30 and 80:" <getnlcm (ARR, 6) <Endl;
Getchar ();
Return 0;
}

 

I'm dizzy. csdn does not allow text containing g * C * D!

Contact Us

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.