Advertisement
dkeray

Variation of K Elements in N numbers

Jan 13th, 2013
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class VarOfKElem
  6. {
  7.  
  8.     static void VariationsOfKElements(int[]arr ,int n, int index)
  9.     {
  10.         if (index == arr.Length)
  11.         {
  12.             Console.Write("{");
  13.             for (int i = 0; i < arr.Length; i++)
  14.             {
  15.                 Console.Write(arr[i] + ", ");
  16.             }
  17.             Console.WriteLine("}");
  18.         }
  19.         else
  20.         {
  21.             for (int i = 1; i <= n; i++)
  22.             {
  23.                 arr[index] = i;
  24.                 VariationsOfKElements(arr, n, index + 1);
  25.             }
  26.         }
  27.     }
  28.  
  29.  
  30.     static void Main()
  31.     {  
  32.         int n = int.Parse(Console.ReadLine());
  33.         int k = int.Parse(Console.ReadLine());    
  34.         int[] arr = new int[k];
  35.         VariationsOfKElements(arr, n, 0);  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement