求2數的3位組合, 如輸入0,1, 需輸出:
000
001
010
011
111
110
100
101

解决方案 »

  1.   

    http://www.cnblogs.com/rogerwei/archive/2010/11/18/1880336.html
      

  2.   


                int[] ary = { 0, 1 };
                var source = from t1 in ary from t2 in ary from t3 in ary select new { s = "" + t1 + t2 + t3 };
                foreach (var t in source)
                    Console.WriteLine(t.s);
      

  3.   

    这个用二进制就可以了。
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                char first = '0', second = '1';
                for (int i = 0; i < 8; i++)
                {
                    string r = "";
                    for (int j = 0; j < 3; j++)
                    {
                        if ((i >> j) % 2 == 0) r += first; else r += second;
                    }
                    Console.WriteLine(r);
                }
            }
        }
    }000
    100
    010
    110
    001
    101
    011
    111
    Press any key to continue . . .