Advertisement
Fanta-MindTerror

isSimple

Dec 24th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             while (true)
  6.             {
  7.                 Console.WriteLine("Введите первое число");
  8.                 int N = Convert.ToInt32(Console.ReadLine());
  9.                 Console.WriteLine("Результат "+ isSimple(N));
  10.             }
  11.         }
  12.  
  13.         static bool isSimple(int N)
  14.         {
  15.             if( N <= 1)
  16.             {
  17.                 return false;
  18.             }
  19.             if( N == 2)
  20.             {
  21.                 return false;
  22.             }
  23.             bool si = true;
  24.             int i = N-1;
  25.             while(i > 0)
  26.             {
  27.                 if (i > 1)
  28.                 {
  29.                     if (N % i == 0)
  30.                     {
  31.                         si = false;
  32.                     }
  33.                 }
  34.                 i--;
  35.             }
  36.             return si;
  37.         }
  38.  
  39.      
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement