/***************************************************************
C语言
AUTHOR:liuyongshui
DATE:********
问题来源:http://blog.csdn.net/sxhelijian/article/details/8620846
***************************************************************/
/*
问题十二:编写模板函数sort,功能是:对三个形参a, b, c按照从大到小排序。
*/
#include <stdio.h>
void sort(int l, int m, int n); //原函数的申明
int main()
{
int a;
int b;
int c;
printf("请输入三个数:");
scanf("%d %d %d", &a, &b, &c);
sort(a, b, c);
return 0;
}
// 函数的定义
void sort(int l, int m, int n)
{
int t;
if(l<m) //比较l和m的大小
{
t=l;
l=m;
m=t;
}
if(l<n) //比较l和n的大小
{
t=l;
l=n;
n=t;
}
if(m<n) //比较m和n的大小
{
t=m;
m=n;
n=t;
}
printf("排序后,由大到小:%d %d %d\n", l, m, n);
}
C语言
AUTHOR:liuyongshui
DATE:********
问题来源:http://blog.csdn.net/sxhelijian/article/details/8620846
***************************************************************/
/*
问题十二:编写模板函数sort,功能是:对三个形参a, b, c按照从大到小排序。
*/
#include <stdio.h>
void sort(int l, int m, int n); //原函数的申明
int main()
{
int a;
int b;
int c;
printf("请输入三个数:");
scanf("%d %d %d", &a, &b, &c);
sort(a, b, c);
return 0;
}
// 函数的定义
void sort(int l, int m, int n)
{
int t;
if(l<m) //比较l和m的大小
{
t=l;
l=m;
m=t;
}
if(l<n) //比较l和n的大小
{
t=l;
l=n;
n=t;
}
if(m<n) //比较m和n的大小
{
t=m;
m=n;
n=t;
}
printf("排序后,由大到小:%d %d %d\n", l, m, n);
}