Top 25 Programming Puzzles and Brain Teasers

转自:Top 25 Programming Puzzles and Brain Teasers


  1. Add two numbers without using addition operator | 4 methods
  2. Implement power function without using multiplication and division operators
  3. Print all numbers between 1 to N without using semicolon
  4. Swap two numbers without using third variable | 5 methods
  5. Determine the if condition to print specific output
  6. Find maximum, minimum of three numbers without using conditional statement and ternary operator | 4 methods
  7. Find numbers represented as sum of two cubes for two different pairs
  8. Print “Hello World” with empty main() function | 3 methods
  9. Print all numbers between 1 to N without using any loop | 4 methods
  10. Print a semicolon without using semicolon anywhere in the program
  11. Multiply two numbers without using multiplication operator or loops
  12. Find square of a number without using multiplication and division operator | 3 methods
  13. Find if a number is even or odd without using any conditional statement
  14. Set both elements of a binary array to 0 in single line
  15. Find minimum number without using conditional statement or ternary operator
  16. Perform Division of two numbers without using division operator
  17. Generate 0 and 1 with 75% and 25% Probability
  18. Generate Desired Random Numbers With Equal Probability
  19. Return 0, 1 and 2 with equal Probability using the specified function
  20. Generate Fair Results from a Biased Coin
  21. Generate numbers from 1 to 7 with equal probability using specified function
  22. Implement Ternary Operator Without Using Conditional Expressions
  23. Determine if two integers are equal without using comparison and arithmetic operators
  24. Return 0 and 1 with equal Probability using the specified function
  25. Clock angle problem – Find angle between hour and minute hand