C语言实验——从大到小输出a、b、c(选择结构)
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
从键盘输入三个整数a、b、c,要求将输出的数据按从大到小排序后输出。
Input
从键盘上输入三个整数a、b、c,每个整数之间用空格分开。
Output
从大到小顺序输出a、b、c的值。
Example Input
4 3 5
Example Output
5 4 3
注意:三个数比较,始终让第一个数最大,第二个数次之,如果第一个数比其他两个数小,就交换位置,第二个数比第三个数小也交换。
#include<stdio.h> int main() { int a, b, c, d; scanf("%d %d %d",&a, &b, &c); if(a < b) { d = a; a = b; b = d; } if(a < c) { d = c; c = a; a = d; } if(c > b) { d = b; b = c; c = d; } printf("%d %d %d\n",a, b, c); return 0; }