class Program { static void Main(string[] args) { getPairs(3, 0, 0, 1, ""); Console.ReadKey(); } private static void getPairs(int close, int left, int right, int inter, string backet) { if (left == close && right == close) { Console.Write(backet + ", "); } if (left < close) { getPairs(close, left + 1, right, inter++, backet + "("); } if (right < left) { getPairs(close, left, right + 1, inter++, backet + ")"); } } }