CSharp examples for Data Structure Algorithm:Algorithm
Calculates the greatest common divisor (GCD) of given two numbers. Use the Euclidean algorithm.
using System;/*from w ww . ja va 2s . co m*/ class GCD { static void Main() { int num1 = int.Parse(Console.ReadLine()); int num2 = int.Parse(Console.ReadLine()); while (num1 != 0 && num2 != 0) { if (num1 > num2) { num1 -= num2; } else { num2 -= num1; } } Console.WriteLine(Math.Max(num1, num2)); } }