Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace zadanie_17
- {
- class Program
- {
- static void Main(string[] args)
- {
- ulong gorny_zakres, pierwszy, drugi;
- Console.WriteLine("Program wypisujący wszystkie liczby doskonałe z przedziału od 1 do zadanej z klawiatury wartości.");
- gorny_zakres = Liczba("podaj górny zakres",
- "Wprowadź poprawną wartość!!!");
- for (ulong i = 2; i <= gorny_zakres; i++) // if PN
- if (PrimeNumbers(i))
- {
- pierwszy = i;
- for (ulong j = 2; j <= gorny_zakres; j++)
- if ((PrimeNumbers(j)) && (j != i))
- {
- drugi = j;
- if (drugi - pierwszy == 2)
- {
- Console.WriteLine("{0},{1}", pierwszy, drugi);
- break;
- }
- }
- }
- }
- static ulong Liczba(string prompt, string ErrorMessage)
- {
- ulong liczba;
- while (true)
- {
- Console.WriteLine(prompt);
- if (ulong.TryParse(Console.ReadLine(), out liczba) == true) return liczba;
- else Console.WriteLine(ErrorMessage);
- }
- }
- static bool PrimeNumbers(ulong number)
- {
- if (number < 2) return false;
- else if (number == 4) return false;
- else
- for (uint i = 1; i <= number; i++)
- if (number % i == 0) return false;
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement