/* (Start of program header annotation)
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: enter two integers to obtain the minimum public multiple and maximum public approx.
* Author: Lei hengxin
* Completion date: January 1, September 08, 2012
* Version No.: V1.0
* Description of tasks and Solutions
* Programming philosophy:
* Input description:
* Problem description:
* Program output:
* End the comment in the program Header
*/
[Csharp]
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace ConsoleApplication_do_while
{
Class Program
{
Static void Main (string [] args)
{
Console. WriteLine ("this is a program that inputs two integers to calculate the least common multiple of the two integers and the maximum common number ");
Console. Write ("Enter the first INTEGER :");
String first = Console. ReadLine ();
Console. Write ("enter the second INTEGER :");
String second = Console. ReadLine ();
Int x = int. Parse (first); // type conversion
Int y = int. Parse (second); // type conversion
Int Greatest_common_divisor = gcd (x, y );
Int Least_common_multiple = lcm (x, y );
Console. WriteLine ("The minimum public multiples of {0} and {1} are: {2} The maximum public approx. Is: {3}", x, y, Least_common_multiple, Greatest_common_divisor );
Console. ReadKey ();
}
// Calculate the maximum public approx.
Static int gcd (int m, int n)
{
Int I = 2; // define the cyclic control variable
Int Least_common_multiple = 1; // calculates the maximum common approx.
Int min1 = min (m, n );
While (I <= min1)
{
While (m % I = 0 & n % I = 0) // calculates the common divisor of the denominator.
{
M = m/I;
N = n/I;
Min1 = min (m, n );
Least_common_multiple = Least_common_multiple * I;
}
++ I;
}
Return Least_common_multiple;
}
// Calculate the minimum public multiple
Static int lcm (int m, int n)
{
Int Greatest_common_divisor = gcd (m, n); // calculates the maximum public approx.
Int Least_common_multiple = (m/Greatest_common_divisor) * (n/Greatest_common_divisor) * Greatest_common_divisor; // The minimum public multiple has a certain relationship with the maximum public approx.
Return Least_common_multiple;
}
// Calculate the maximum and minimum values of two numbers
Static int min (int m, int n)
{
Int min;
If (m> n)
{
Min = n;
}
Else
{
Min = m;
}
Return min;
}
}
}
Running result: