Skip to content

Commit

Permalink
Strange one-liners that swaps value of two variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhasKamal authored Jul 27, 2017
1 parent 56d8c38 commit c762d2d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion one_line_swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ main(){

// Bonus- Get the max number without using logical operation
int m = (a+b+((a-b)>>sizeof(int)*8-1|1)*(a-b))/2; // Developer- Minhas Kamal (https://minhaskamal.github.io)
// Details- http://i.imgur.com/6Z2J1NF.png
// Details- https://www.quora.com/How-can-I-find-the-maximum-of-two-numbers-without-using-if-else-or-any-other-comparison-operator/answer/Minhas-Kamal
// Another Solution- If both both numbers are positive
// then this works too:
// m = (int[]){a,b}[1-!!(a/b)]
Expand Down

0 comments on commit c762d2d

Please sign in to comment.