比如“1,2,3....10”,1到10這10個數,顯示他的所有可能組合情況(排列順序無所謂)

來源:互聯網
上載者:User
#include <stdio.h>#include <stdlib.h>#define MAX_NUM 26int comb[MAX_NUM];int c1,c2;void combination(int m,int n) {    int i,j;     for (i=m;i>=n;i--) {        comb[n]=i; /* 選擇當前的“頭”元素 */.        if (n>1) {            combination(i-1,n-1); /* 進入下一次更小的組合問題 */.        } else { /* 滿了需要的組合數,輸出 */.            for (j=comb[0];j>0;j--) printf("%c",'A'+c1-comb[j]);            printf("\n");        }    }    return;}int main(int argc,char **argv) {    if (argc<3) {        printf("%s 組合下標 組合上標\n",argv[0]);        return 1;    }    c1=atoi(argv[1]);    if (c1<1 || MAX_NUM<c1) {        printf("1<=組合下標<=%d\n",MAX_NUM);        return 2;    }    c2=atoi(argv[2]);    if (c2<1 || c1<c2) {        printf("1<=組合上標<=組合下標\n");        return 3;    }    comb[0]=c2;    combination(c1,c2);    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.