The first example of 100 classic examples of C language

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:
insert image description here

Guess you like

Origin blog.csdn.net/Demondai999/article/details/122845311
Recommended