- #include <stdio.h>
- int main() {
-
- int count = 0 ; //用来计算满足条件有多少个
- //三重循环
- for (int i = 1; i <= 4; i++) { //i从1到4
- for (int j = 1; j <= 4; j++) { //j从1到4
- if (i != j) { //但i,j不能相等
- for (int k = 1; k <= 4; k++) { //k从1到4
- if (i != k && j != k) { //由于i != j,把满足i != j != k 的排列组合打印出来
- count++ ;
- printf("i = %d,j = %d,k =%d\n",i,j,k);
- }
- }
- }
- }
- }
-
- printf("count = %d\n",count);
- return 0 ;
- }
复制代码 |