【问题标题】:how to generate combination of number length 2 in asp.net c#如何在asp.net c#中生成数字长度2的组合
【发布时间】:2018-11-12 10:01:32
【问题描述】:

我有 1-9 位数字,想生成不重复和重复的数字的概率(组合)。

int[] array = {1, 2, 3, 4};

我需要这样的输出:

{1,2}{1,3}{1,4}{2,1}{2,3}{2,4}{3,1}{3,2}{3,4}{1,1}{2,2}{3,3}{4,4}

【问题讨论】:

  • 你也要{4,1}{4,2}{4,3}吗?

标签: combinations permutation probability


【解决方案1】:

做这样的事情。

for(int i = 0 ; i < array.size() ; i ++){
for(int j = i + 1; j < array.size() ;j++)
 {
    int first = array[i];
    int second = array[j];
    //Do someting.
 }
}

【讨论】:

    猜你喜欢
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    • 2011-06-11
    • 1970-01-01
    相关资源
    最近更新 更多