Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- int a;
- string nacteni;
- Console.Write("Napiš prvočíslo: ");
- nacteni = Console.ReadLine();
- a = Convert.ToInt32(nacteni);
- Console.Write("Vybrali jste číslo " + a);
- if (jePrvocislo(a) == true)
- Console.WriteLine(", které je prvočíslo.");
- else
- Console.WriteLine(", které není prvočíslo.");
- Console.ReadLine();
- }
- static bool jePrvocislo(int a)
- {
- int b = 0;
- for (int i = 1; i < a+1; i++)
- {
- if (a % i == 0)
- {
- b++;
- }
- }
- if (a == 2)
- {
- b++;
- }
- if (b <= 2)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement