Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class GCD
- {
- static void Main()
- {
- Console.WriteLine("Find the GCD (Greatest Common Denominator) of two numbers.");
- Console.Write("Input first number: ");
- string num1 = Console.ReadLine();
- int x = Int32.Parse(num1);
- Console.Write("Input second number: ");
- string num2 = Console.ReadLine();
- int y = Int32.Parse(num2);
- while (x != 0 && y != 0)
- {
- if (x > y)
- {
- x %= y;
- }
- else
- {
- y %= x;
- }
- }
- int gcd = (int)Math.Max(x,y);
- Console.WriteLine("The greatest common denominator of the numbers {0} and {1} is: {2}", num1, num2, gcd);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment