Advertisement
gabi11

Algorithms - 4. Generating 0/1 Vectors

Aug 31st, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Recursion
  5. {
  6.     class Program
  7.     {
  8.         static void Generate(int index, int[] arr)
  9.         {
  10.             if (index == arr.Length)
  11.             {
  12.                 Console.WriteLine(string.Join("", arr));
  13.             }
  14.  
  15.             else
  16.             {
  17.                 for (int i = 0; i <= 1; i++)
  18.                 {
  19.                     arr[index] = i;
  20.                     Generate(index + 1, arr);
  21.                 }
  22.             }
  23.         }
  24.         static void Main(string[] args)
  25.         {
  26.             var number = int.Parse(Console.ReadLine());
  27.             var arr = new int[number];
  28.  
  29.             Generate(0, arr);
  30.         }
  31.  
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement