Examples of five C language

Title: Enter three integers x, y, z, please these three numbers small to large outputs.

Program analysis: We find a way to put the smallest number x, x and y are compared first, if x> y then the x and y values ​​are exchanged, and then use the x and z are compared, if x> z x will be exchanged with the value of z, and x can be minimized.

#include <stdio.h>
int main()
{
int x,y,z,t;
printf("\n请输入三个数字:\n");
scanf("%d%d%d",&x,&y,&z);
if (x>y) { /*交换x,y的值*/
    t=x;x=y;y=t;
}
if(x>z) { /*交换x,z的值*/
    t=z;z=x;x=t;
}
if(y>z) { /*交换z,y的值*/
    t=y;y=z;z=t;
}
printf("从小到大排序: %d %d %d\n",x,y,z);
}

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_44097082/article/details/95093710