Comparing two integers without any comparison

前端 未结 14 1824
温柔的废话
温柔的废话 2020-12-05 16:06

Is it possible to find the greatest of two integers without any comparison? I found some solutions:

if(!(a/b)) // if a is less than b then division result          


        
14条回答
  •  旧时难觅i
    2020-12-05 16:29

    (!(a/b) ?  cout << " b is greater than a" : (!(b-a) ? cout << "a and b are equal" :  cout << "a is greater than b") :  cout << "a is greater than b");
    

    That gets a bit messy though

    Edit: Is this homework?

提交回复
热议问题