Visual C++ 6.0对任意三个数字进行排序

 1 # include <stdio.h>
 2 int main (void)
 3 {
 4     int a, b, c;
 5     int t;
 6     printf("请输入三个整数,中间以空格隔开:");
 7     scanf("%d %d %d", &a, &b, &c);
 8     if (a < b)
 9     {
10         t = a;
11         a = b;
12         b = t;
13     }
14     if (a < c)
15     {
16         t = a;
17         a = c;
18         c = t;
19     }
20     if (b < c)
21     {
22         t = b;
23         b = c;
24         c = t;
25     }
26     printf("%d %d %d\n", a, b, c);
27 
28 
29     return 0;
30 }

这个程序是要把两个个数字都要进行比较,然后再排序。只要一个数比一个数大,就把大的数放到前面去。

 

posted on 2018-12-10 22:18  StaryLL  阅读(716)  评论(0)    收藏  举报

导航