用1、2、3、4组成不重复三位数的C语言实现
#include <stdio.h>
int main() { int count = 0; // 记录符合条件的三位数个数 for(int i = 1; i <= 4; i++) // 百位数 { for(int j = 1; j <= 4; j++) // 十位数 { if(j == i) // 十位数与百位数相同,跳过 continue; for(int k = 1; k <= 4; k++) // 个位数 { if(k == i || k == j) // 个位数与百位数或十位数相同,跳过 continue; printf('%d%d%d ', i, j, k); // 输出符合条件的三位数 count++; // 符合条件的三位数个数加1 } } } printf("\n共有%d个三位数符合条件。\n", count); // 输出符合条件的三位数个数 return 0; }
原文地址: https://www.cveoy.top/t/topic/n6y8 著作权归作者所有。请勿转载和采集!