Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //find two max and sum
- if(a>b){
- if(b>c){
- //a>b>c => sum a+b
- }else{
- //a>b and c>b => sum a+c
- }
- }else{
- if(a>c){
- //b>=a>c => sum a+b
- }else{
- //c>b>=a => sum c+b
- }
- }
- //find smallest, and sum the others
- s0=0 //introduce another 2-bit variable called s
- s1=0 //it essentially keeps the sign of the addition between the comparisons
- if(a>b){
- s0=1
- }
- if(b>c){
- s1=1
- }
- //s = 00 then a<=b and b<=c, a is smallest
- //s = 01 then a>b and b<=c, b is smallest
- //s = 10 then a>b and b>c, c is smallest
- if s = 00, sum c+b
- if s = 01, sum c+a
- if s = 10, sum a+b
- //as you can see in the 3 if statements above
- //whenever s has a 1 somewhere, then a should be added
- //whenever s0 is 0 then b should be added
- //whenever s1 is 0 then c should be added
Add Comment
Please, Sign In to add comment