C Practice Example 1
Question : There are 1, 2, 3, 4 numbers, how many three-digit numbers that are different from each other and have no repeated numbers can be formed? How much are they?
Program analysis : The numbers that can be filled in the hundreds, tens, and ones are all 1, 2, 3, and 4. After all the permutations are formed, the permutations that do not meet the conditions are removed.
int main() {
int a, b, c,d = 0;
for (a = 1; a < 5; a++) {
for (b = 1; b < 5; b++) {
for (c = 1; c < 5; c++) {
if (a != b && a != c && b != c) {
d++;
printf("%d: %d %d %d\n", d, a, b, c);
}
}
}
}
return 0;
}
Example output: