Size of three numbers in C language and three in C Language
Take 1 2 3 as an example to consider all possible input types (not listed here): 1 2 3; 3 2 1; 2 1 3; 1 1 1; 1 2 2; 1 2 1; the overall idea is to take two numbers from the input three numbers, select the largest of the two numbers and compare the maximum number with the third number. For more information, see the code;
Code:
# Include
Int comp (int x, int y)
{
Return x> y? X: y;
}
Int main ()
{
Int I, j, k;
Int a, B, c;
Scanf ("% d", & a, & B, & c );
J = comp (a, B); // j indicates the maximum value of the two numbers.
K = c; // a + B-j calculates the smaller number in a and B;
If (j-k <0) {printf ("% d", k, j, a + B-j); return 0 ;} // indicates that K can be output in sequence at most 1 2 3; 2 2 2 3
If (j-k> = a + B-j) {printf ("% d", j, a + B-j, k); return 0 ;} // 3 2 1
If (j-k
}
Summary:
In fact, the essence of this Code is similar to that of the if statement. However, you do not need to call three if statements every time. Therefore, an if statement can output more efficient answers.