Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Lab1_wariacje_bez_powtorzen
  4. {
  5. class kom_bez_powt
  6. {
  7. private static int numberofCombos;
  8. private static int n;
  9. private static int k;
  10. private static int[] storageArr;
  11.  
  12. public static void Main()
  13. {
  14. n = 5;
  15. k = 3;
  16. storageArr = new int[k];
  17.  
  18. GenCombinationsNoRep();
  19. Console.ReadKey();
  20. }
  21.  
  22. private static void GenCombinationsNoRep(int index = 0, int element = 0)
  23. {
  24. if (index >= storageArr.Length)
  25. {
  26. PrintCombo();
  27. return;
  28. }
  29.  
  30. for (int i = element; i < n; i++)
  31. {
  32. storageArr[index] = i;
  33. GenCombinationsNoRep(index + 1, i + 1);
  34. }
  35. }
  36.  
  37. private static void PrintCombo()
  38. {
  39. Console.WriteLine(
  40. "{0,3}: [{1}]",
  41. ++numberofCombos,
  42. string.Join(", ", storageArr));
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement