【C語言】有2、4、6、8共4個數字,能組成多少個互不相同且無重複數字的三位數?都是多少?請編程輸出所有的這些三位數及它們的總個數。

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
    int a[4] = {2,4,6,8};
    int count=0,i,j,k;
    for(i=0; i<4; i++){
        for(j=0; j<4; j++){
            for(k=0; k<4; k++){
                if(i!=j&&i!=k&&j!=k){
                    printf("%d%d%d\n", a[i], a[j], a[k]);
                    count++;
                }
            }
        }
    }
    printf("共有%d個\n",count);
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章