红色蚂蚁 -- The Red Ant
团结就是力量 -- Union Gives Strength

导航

 
//两个int类型的数据,不用任何的判断语句如if、switch、?:等,找出其中的大值
#include <stdio.h>
/*
int
max( int x,int y )
{
        int buf[2] = { x, y };
        unsigned int z;
 
        z = x - y;
        z >>= 31;
 
        return buf[z];
}
*/
int
max( int x,int y )
{
        int buf[2]={x,y};
        unsigned int z;
        int c;
 
        z = x - y;
        c = x - y;
        z >>= 31;
        z= 0 ^ z;
 
        return buf[z];
}
 
 
int
main( int argc, char *argv[] )
{
        int buf[2];
 
        if( argc != 3 )
        {
                printf( "USEG error" );
                return -1;
        }
        buf[0] = atoi(argv[1]);
        buf[1] = atoi(argv[2]);
 
        printf( "The max num is %d\n", max( buf[0], buf[1] ) );
 
        return 0;
}
posted on 2004-10-13 13:39  红色蚂蚁  阅读(785)  评论(0)    收藏  举报