Common algorithms (C #): calculate the maximum common divisor of a number.

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace exmaxgongyueshu

{
Class maxgongyueshu
{
Public float maxgongyueshu (INT N1, int N2)
{
Int temp = math. Max (N1, N2 );
N2 = math. Min (N1, N2); // N2 stores the smallest of the two numbers
N1 = temp; // the largest of the two numbers in N1
While (N2! = 0)
{
N1 = N1> N2? N1: N2; // make the number in N1 greater than the number in N2
Int M = N1 % N2;
N1 = n2;
N2 = m;
}

Return N1;
}
Static void main (string [] ARGs)
{
Int n1 = convert. toint32 (console. Readline ());
Int n2 = convert. toint32 (console. Readline ());
If (N1 * N2! = 0)
{
Maxgongyueshu M = new maxgongyueshu ();
Console. writeline (M. maxgongyueshu (N1, N2 ));
}
Else
{
Console. writeline ("the two numbers cannot be 0. ");
}
}
}
}

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.