Posted By

zaxbbun on 05/21/13


Tagged

max


Versions (?)

max: compare two numbers withou using [if, switch, :?]


 / Published in: C
 

max: compare two numbers withou using [if, switch, :?]

  1. // solution one
  2. //
  3. template <class T>
  4. T max(T a, T b){
  5. return (a + b + abs(a - b)) / 2;
  6. }
  7.  
  8.  
  9. // solution two
  10. //
  11. template <class T>
  12. T max(T a, T b){
  13. T num[2] = [a, b];
  14. return num[a < b];
  15. }

Report this snippet  

You need to login to post a comment.