将形参指针所指的四个整数中找到最大值和最小值,最大值放在a中,最小放在d中

#include 
void fun(int* a, int* b, int* c, int* d)
{
	int t = 0;
	if (*a < *b) { t = *a; *a = *b; *b = t; }
	if (*a < *c) { t = *a; *a = *c; *c = t; }
	if (*a < *d) { t = *a; *a = *d; *d = t; }
	if (*b < *c) { t = *b; *b = *c; *c = t; }
	if (*b < *d) { t = *b; *b = *d; *d = t; }
	if (*c < *d) { t = *c; *c = *d; *d = t; }
}
int main()
{
	int a, b, c, d;
	printf("请输入4个整数: ");
	scanf("%d%d%d%d", &a, &b, &c, &d);
	printf("原始顺序:%d,%d,%d,%d\n", a, b, c, d);
	fun(&a, &b, &c, &d);
	printf("处理后:%d,%d,%d,%d\n", a, b, c, d);
}

你可能感兴趣的:(算法,数据结构,c语言)