Advertisement
stanevplamen

02.01.21.Combinations

Jul 2nd, 2013
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2.  
  3. public static class GlobalMembersCombinationsWithoutRepetition
  4. {
  5.     public static int n;
  6.     public static int k;
  7.     public static int[] numbersArray = new int[20];
  8.     public static void Print(uint length)
  9.     {
  10.         for (int i = 0; i < length; i++)
  11.         {
  12.             Console.Write("{0:D} ", numbersArray[i]);
  13.         }
  14.         Console.Write("\n");
  15.     }
  16.     public static void Komb(uint i, uint after)
  17.     {
  18.         uint j;
  19.         if (i > k)
  20.             return;
  21.         for (j = after + 1; j <= n; j++)
  22.         {
  23.             numbersArray[i - 1] = (int)j;
  24.             if (i == k)
  25.             {
  26.                 Print(i);
  27.             }
  28.             Komb(i + 1, j);
  29.         }
  30.     }
  31.     static int Main()
  32.     {
  33.         Console.Write("Please enter N = ");
  34.         n = int.Parse(Console.ReadLine());
  35.         Console.Write("Please enter K = ");
  36.         k = int.Parse(Console.ReadLine());
  37.         Console.Write("C({0:D},{1:D}): \n", n, k);
  38.         Komb(1, 0);
  39.         return 0;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement