Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. public static string ZwrocNieparzyste1(int[] tab, int i)
  2. {
  3. if ((i == (tab.Length - 1)) )
  4. {
  5. if (((tab[i] & 1) == 1))
  6. {
  7. return "," + tab[i];
  8. }
  9.  
  10. else
  11. {
  12. return String.Empty;
  13. }
  14. }
  15. if ((tab[i] & 1) == 1)
  16. {
  17. return tab[i]+ ","+ ZwrocNieparzyste1(tab, ++i);
  18. }
  19.  
  20. return ZwrocNieparzyste1(tab,++i);
  21. }
  22. liczba&1 - maskowanie na bit parzystości czyt. sprawdzanie jego wartości. Jak jest liczba w systemie binarnym to jak jej pierwszy bit (numerowany jako 0 od prawej) ma wartość 0 to jest to liczba parzysta, a jak 1 to nieparzysta.
  23. działa tylko dla liczb całkowitych
  24.  
  25.  
  26.  
  27. to zamień &1 na modulo z 2
  28. a String.Empty na ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement