| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4023 人关注过本帖
标题:比较3个数的大小,不用关系运算符只用选择结构语句,不用后面的知识怎么做
只看楼主 加入收藏
makewelldone
Rank: 1
来 自:江苏南京
等 级:新手上路
帖 子:97
专家分:0
注 册:2006-9-25
收藏
得分:0 
回复2
我根据编译器的特性写出上面的程序,它与没有用到关系运算符也没有用到后面的。只有用1 和0;
2007-12-26 21:14
makewelldone
Rank: 1
来 自:江苏南京
等 级:新手上路
帖 子:97
专家分:0
注 册:2006-9-25
收藏
得分:0 
回复3
int findOut(int a,int b,int c)
{
    if(a/(a+1)) // a<0?
    {
        if( b/(b+1)) // b<0
        {
                if(a/b)//a<b
                {
                        if(c/(c+1))//c<0
                        {
                                    if( b /c)//b<c
                                        return c;
                                     else
                                         return b;

                        }
                        else // a<0,b<0,c>=0
                            return c;
                }
                else // a>b
                {
                            if(c/(c+1)) // c<0
                            {
                                            if( a/c) //a<c
                                                return c;
                                            else
                                                return a;
                            }
                            else //a<0,b<0,c>=0
                                return c;
                }
        }//b>0
        else
        {
                            if( c/(c+1))//c<0
                            {
                                return b; //a<0,b>=0,c<0
                            }
                            else //a<0,b>=0,c>=0
                            {
                                                            if( b/c) //b>c
                                                                return b;
                                                            else
                                                                return c;
                            }
                            
        }
    }
    else //a>=0
    {
        if( b/(b+1))
        {
            if(c/(c+1))//a>=0,b<0,c<0
                return a;
             else // a>=0,b<0,c>=0
             {
                 if(a/c)
                     return a;
                 else
                     return c;
             }
        }
        else
        {
            if(a/b) //a>b
            {
                if(c/(c+1))
                {
                    return a;
                }
                else
                {
                    if(a/c)
                        return a;
                    else
                        return c;
                }
            }
            else//a<b
            {
                if(c/(c+1))
                    return b;
                else
                {
                    if(b/c)
                        return b;
                    else
                        return c;
                }
            }
        }
    }
    
    return a;
}
这个算法只能用没有0的情况,有0时问题就更简单了,你可以自已来写
2007-12-27 14:53
低头是人间
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2023-8-28
收藏
得分:0 
不使用关系运算符应该是不能出现>或<等比较类的符号
#include <stdio.h>
int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int d=(a-b)>>31;
    int e=(b-c)>>31;
    int f=(a-c)>>31;
    if(d==f==1){
        printf("a\n");
    }
    if(d==f==0){
        if(e==0){
            printf("c\n");
        }
        if(e==1){
            printf("b\n");
        }
    }
}
2023-08-28 17:02
快速回复:比较3个数的大小,不用关系运算符只用选择结构语句,不用后面的知识怎 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.064329 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved