Guest User

Untitled

a guest
Oct 22nd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. //find two max and sum
  2. if(a>b){
  3. if(b>c){
  4. //a>b>c => sum a+b
  5. }else{
  6. //a>b and c>b => sum a+c
  7. }
  8. }else{
  9. if(a>c){
  10. //b>=a>c => sum a+b
  11. }else{
  12. //c>b>=a => sum c+b
  13. }
  14. }
  15.  
  16. //find smallest, and sum the others
  17. s0=0 //introduce another 2-bit variable called s
  18. s1=0 //it essentially keeps the sign of the addition between the comparisons
  19. if(a>b){
  20. s0=1
  21. }
  22. if(b>c){
  23. s1=1
  24. }
  25.  
  26. //s = 00 then a<=b and b<=c, a is smallest
  27. //s = 01 then a>b and b<=c, b is smallest
  28. //s = 10 then a>b and b>c, c is smallest
  29.  
  30. if s = 00, sum c+b
  31. if s = 01, sum c+a
  32. if s = 10, sum a+b
  33.  
  34. //as you can see in the 3 if statements above
  35. //whenever s has a 1 somewhere, then a should be added
  36. //whenever s0 is 0 then b should be added
  37. //whenever s1 is 0 then c should be added
Add Comment
Please, Sign In to add comment