Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp20
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] tab =
- {
- 2, 3, 5, 7, 11, 13
- };
- Console.WriteLine(IleSekwencji(tab));
- Console.ReadKey();
- }
- static int IleSekwencji(int[] tab)
- {
- int ile = 0;
- int liczba;
- for (int i = 0; i < tab.Length-1; i++)
- {
- liczba = tab[i];
- if (CzyPierwsza(liczba))
- {
- liczba = tab[i + 1];
- if (CzyPierwsza(liczba))
- {
- ile++;
- }
- }
- }
- return ile;
- }
- static bool CzyPierwsza(int liczba)
- {
- if (liczba == 2) return true;
- for (int i = 2; i < liczba; i++)
- {
- if (liczba % i == 0)
- {
- return false;
- }
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement