Advertisement
ntamas

Prímteszt másképp

Nov 6th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1.     static bool isprime(int szam)
  2.     {
  3.       int count = 0;
  4.       if (szam < 0)
  5.       {
  6.         szam = -szam;
  7.       }
  8.       if (szam < 2)
  9.       {
  10.         return false;
  11.       }
  12.       else if (szam == 2)
  13.       {
  14.         return true;
  15.       }
  16.       else
  17.       {
  18.         for (int i = 2; i < szam; i++)
  19.         {
  20.           if (szam % i != 0)
  21.           {
  22.             count++;
  23.           }
  24.         }
  25.         if (count == szam - 2)
  26.         {
  27.           return true;
  28.         }
  29.         else
  30.         {
  31.           return false;
  32.         }
  33.       }
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement