"Program 1"
Title: There are 1, 2, 3, 4 numbers, can make up how many different and no repetition of the number of three digits? How much are they?
1. Program Analysis: Can be filled in the hundred, 10 digits, digit digits are 1, 2, 3, 4. make all the permutations and then remove the permutations that do not meet the criteria .
2. Program Source code:
#include "stdio.h" #include "conio.h" main () { int i,j,k; printf ("\ n"); for (i=1;i<5;i++)/* The following is a triple loop */For (j=1;j<5;j++) for (k=1;k<5;k++) { if (i!=k&&i!=j &&J!=K)/* Make sure I, J, K three bits are different */ printf ("%d,%d,%d\n", i,j,k); } Getch ();}
I think the most used idea in this program is to first combine all three digits and remove the number of unsatisfied conditions.
In fact, my first idea is: put a number on the top, then the second place with the first different number, the third place with the 12th number of different numbers, this idea is actually feasible, but the implementation of the program, you will find a lot more than the above procedure. So the idea of people and the operation of the machine is very different, want to write a good C language program, it is important to learn C program thinking mode.
All say the algorithm is very difficult, all think the algorithm is very tall, but I think this simple small program is an algorithm, because it solves a problem, can solve the problem of the program can be considered algorithm
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C Language Learning 1