// Description: Command-line calculator for greatest common divisor of // integer pairs. // Date: 2011-05-12 Khu namespace ProblemSolvers { class GcdProblemSolver { protected const string Hint = "Please call the gcd problem solver with integer pairs as arguments! "; public static void Main (string[] args) // Given integer pairs as command arguments, // print their greatest common divisor. { // The following should not be possible: Problems.GcdSolution solution = new Problems.GcdSolution(); solution.Set(4); if (args.Length < 2) { System.Console.WriteLine("Missing Argument. " + Hint); } else { try { Problems.GcdProblemQAI gcdProblem = new Problems.GcdProblemQAI(); int p, q; for (int i = 1; i < args.Length; i += 2) { p = System.Convert.ToInt32(args[i-1]); q = System.Convert.ToInt32(args[i]); gcdProblem.Set(p, q); System.Console.WriteLine ("gcd(" + p + ", " + q + ") = " + gcdProblem.Solution().Gcd); } } catch (System.Exception e) { System.Console.WriteLine ("Wrong Argument. " + Hint + e.Message); } } } } }