108

108: date:2021.2.6

在这里插入图片描述要点: if的多次比较

详细代码如下:

#include   <stdio.h>
void NONO();
void  fun(int  *a, int  *b, int  *c, int  *d)
{
    
    
	/*
		遍历所有元素

		找出最大值,最小值 ;  

		赋值给a,d;
	*/

	int max,min;
	max = min = *a;

	if(max < *b)
		max = *b;
	if(min > *b)
		min = *b;
	if(max < *c)
		max = *c;
	if(min > *c)
		min = *c;
	if(max < *d)
		max = *d;
	if(min > *d)
		min = *d;	

	*d = min;
	*a = max;

	/* error:
	int i,j,max = *a,min = *d;
	int x[]={*a, *b,*c,*d};

	for(i = 0; i < 4; i++)
	{
		if(x[i] > max)
			*a = x[i];
	}
	for(j = 0; j < 4; j++)
	{
		if(x[j] < min)
			*b = x[j];
	}
	*/

}
void 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);
   NONO();
}

猜你喜欢

转载自blog.csdn.net/weixin_44856544/article/details/113732605
108