Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. int a;
  4. string nacteni;
  5. Console.Write("Napiš prvočíslo: ");
  6. nacteni = Console.ReadLine();
  7. a = Convert.ToInt32(nacteni);
  8. Console.Write("Vybrali jste číslo " + a);
  9. if (jePrvocislo(a) == true)
  10. Console.WriteLine(", které je prvočíslo.");
  11. else
  12. Console.WriteLine(", které není prvočíslo.");
  13.  
  14. Console.ReadLine();
  15. }
  16. static bool jePrvocislo(int a)
  17. {
  18. int b = 0;
  19. for (int i = 1; i < a+1; i++)
  20. {
  21. if (a % i == 0)
  22. {
  23. b++;
  24. }
  25. }
  26. if (a == 2)
  27. {
  28. b++;
  29. }
  30. if (b <= 2)
  31. {
  32. return true;
  33. }
  34. else
  35. {
  36. return false;
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement