返回列表 發帖
  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.             int tmp;
  16.             if (x1 > x2)
  17.             {
  18.                 tmp = x1;
  19.                 x1 = x2;
  20.                 x2 = tmp;
  21.             }
  22.             if (x1 <= 0 || x2 > 100)
  23.                 throw new ArgumentException();//使用指定的錯誤訊息。
  24.             bool foundFactor;
  25.             for(int n=Math.Max(x1,2); n<=x2;n++)
  26.             {
  27.                 foundFactor = false;
  28.                 for(int k=2;k<n;k++)
  29.                 {
  30.                     if(n%k==0)
  31.                     {
  32.                         foundFactor = true;
  33.                         break;
  34.                     }
  35.                 }
  36.                 if(!foundFactor)
  37.                 {
  38.                     Console.WriteLine(n);
  39.                 }
  40.             }

  41.         }catch(Exception e)
  42.         {
  43.             Console.WriteLine(e.Message);
  44.             Console.WriteLine("error");

  45.         }
  46.     }
  47.     /*
  48.      * ArgumentException是一個自訂「合法參數」的例外,
  49.      * ArgumentException類別所接受的合法參數,是由程式設計師自行設定的。
  50.      *
  51.      * FormatException當參數格式不符合呼叫的方法的參數規範時引發的異常.
  52.      */


  53. }
複製代碼
istak.teach2@gmail.com

TOP

返回列表