返回列表 發帖
  1. using ConsoleApp1;
  2. using System;//程式庫呼叫
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Linq.Expressions;
  5. using ABC.qq;


  6. class Program//負責一部分工作的人
  7. {
  8.     static void Main()//method ..Entry Point 程式進入點
  9.     {
  10.         try
  11.         {
  12.             int x1, x2;
  13.             x1 = Convert.ToInt32(Console.ReadLine());
  14.             x2 = Convert.ToInt32(Console.ReadLine());
  15.             if (x1 < 0 || x1 > 100 || x2 < 0 || x2 > 100)
  16.             {
  17.                 throw new ArgumentException();
  18.             }
  19.             Console.WriteLine(GCD(x1,x2));
  20.         }
  21.         catch
  22.         {
  23.             Console.WriteLine("error");
  24.         }
  25.     }
  26.     static int GCD(int x1,int x2)
  27.     {
  28.         if (x1 % x2 == 0)
  29.             return x2;
  30.         else
  31.             return GCD(x2, x1 % x2);
  32.     }
  33. }
  34.     /*
  35.      * ArgumentException是一個自訂「合法參數」的例外,
  36.      * ArgumentException類別所接受的合法參數,是由程式設計師自行設定的。
  37.      *
  38.      * FormatException當參數格式不符合呼叫的方法的參數規範時引發的異常.
  39.      */
複製代碼
istak.teach2@gmail.com

TOP

返回列表