X Y Z从大到小排序输出

来源:互联网 发布:node v0.12.0 x64.msi 编辑:程序博客网 时间:2024/06/08 02:34

X Y Z从大到小排序输出
能比较最少的次数。

#include <stdio.h>#include <stdlib.h>void Fun(){ //该算法自大至小依次输出顺序读入的三个整数X, Y, Z的值    int x;    int y;    int z;    int temp;    printf("please input x, y and z use space to sprit:");    scanf("%d %d %d", &x, &y, &z);    if (x < y)//比较x和y    {        temp = x;        x = y;        y = temp;    }    if (y < z)//比较y和z    {        temp = z;        z = y;        //比较x和不是最小的数的大小        if (x >= temp)        {            y = temp;        }        else        {            y = x;            x = temp;         }    }    printf("x = %d, y = %d, z = %d", x, y, z); }int main(void){    Fun();      system("pause");    return 0;}
0 0
原创粉丝点击