天天看點

求四個數的最大值與最小值(隻用四個if語句)

# include<stdio.h>
 int main(void)
{	
	 int a, b, c, d,m1,m2,n1,n2,m,n;
	 printf("enter 4 num:");
	 scanf_s("%d%d%d%d", &a, &b, &c, &d);
	 if (a > b)
		 m1 = a, n1 = b;
	 else
		 m1 = b, n1 = a;
	 if (c > d)
		 m2 = c, n2 = d;
	 else
		 m2 = d, n2 = c;
	 if (m1 > m2)
		 m = m1;
	 else
		 m = m2;
	 if (n1 > n2)
		 n = n2;
	 else
		 n = n1;
	 printf("largest is :%d", m);
	 printf("smallest is :%d", n);


		 
}
           

繼續閱讀