Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main(string[] args)
- {
- bool successParse;
- int enteredN;
- int enteredK = 0;
- int minValue, maxValue;
- int firstLeft=1, newLeft=1;
- int tempLeft = 1;
- do
- {
- Console.Write("Enter N: ");
- successParse = int.TryParse(Console.ReadLine(), out enteredN);
- if (successParse)
- {
- Console.Write("Enter K: ");
- successParse = int.TryParse(Console.ReadLine(), out enteredK);
- }
- } while (!successParse);
- if (enteredK > enteredN)
- {
- maxValue = enteredK;
- minValue = enteredN;
- }
- else
- {
- minValue = enteredK;
- maxValue = enteredN;
- }
- if (maxValue%minValue == 0)
- {
- Console.WriteLine("The GCD is: {0}", minValue);
- return;
- }
- firstLeft = maxValue % minValue;
- newLeft = minValue % firstLeft;
- while (tempLeft != 0)
- {
- tempLeft = firstLeft % newLeft;
- firstLeft = newLeft;
- newLeft = tempLeft;
- }
- Console.WriteLine("The GCD is: {0}", firstLeft);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement