Size of three numbers in C language and three in C Language

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.