fork(1) download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int v, w, x, y;
  5.  
  6. // absolute value
  7. v = 7; printf("abs(%d) = %d\n", v, (v>0)*v+(v<0)*-v);
  8. v = -7; printf("abs(%d) = %d\n", v, (v>0)*v+(v<0)*-v);
  9.  
  10. // power of two
  11. w = 7; printf("is %d a power of two: %d\n", w, w && !(w & (w-1)));
  12. w = 8; printf("is %d a power of two: %d\n", w, w && !(w & (w-1)));
  13.  
  14. // min and max
  15. x = 7; y = 8; printf("min(%d, %d) = %d\n", x, y, y ^ ((x ^ y) & -(x < y)));
  16. x = 7; y = 8; printf("max(%d, %d) = %d\n", x, y, x ^ ((x ^ y) & -(x < y)));
  17.  
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
abs(7) = 7
abs(-7) = 7
is 7 a power of two: 0
is 8 a power of two: 1
min(7, 8) = 7
max(7, 8) = 8