Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace SoftUni_Homework_1_6
- {
- class Program
- {
- /// <summary>
- /// Get the Greatest Common Divisor
- /// </summary>
- /// <param name="num1">first number</param>
- /// <param name="num2">second number</param>
- /// <returns> int value of GCD </returns>
- static int GetGCD(int num1, int num2)
- {
- // Compare the two numbers and assigning the difference to the larger number until the two numbers are equal.
- while (num1 != num2)
- {
- if (num1 > num2)
- {
- num1 = num1 - num2;
- }
- if (num2 > num1)
- {
- num2 = num2 - num1;
- }
- }
- return num1;
- }
- /// <summary>
- /// Get the Least Common Multiple
- /// </summary>
- /// <param name="num1">first number</param>
- /// <param name="num2">second number</param>
- /// <returns> int value of LCM </returns>
- static int GetLCM(int num1, int num2)
- {
- // Get the LCM from the product of the numbers divided by the GCD
- return (num1 * num2) / GetGCD(num1, num2);
- }
- static void Main(string[] args)
- {
- Console.WriteLine("LCM of {0},{1} is {2}", 1234, 3456, GetLCM(1234, 3456));
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement