Given two numbers, return sum of them without using operators + and/or -, and using ++ and/or –.
Input: x = 10, y = 5 Output: 15 Input: x = 10, y = -5 Output: 10
We strongly recommend you to minimize your browser and try this yourself first
The idea is to do y times x++, if y is positive and do y times x– if y is negative.
Thanks to Gaurav Ahirwar for suggesting above solution.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Fill the missing numbers in the array of N natural numbers such that arr[i] not equal to i
- Numbers less than N which are product of exactly two distinct prime numbers
- Check if a given pair of Numbers are Betrothed numbers or not
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Count numbers which are divisible by all the numbers from 2 to 10
- Count numbers which can be constructed using two numbers
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Number of ways to obtain each numbers in range [1, b+c] by adding any two numbers in range [a, b] and [b, c]
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Sum of first n even numbers
- Happy Numbers
- Sum of the first N Prime numbers
- GCD of factorials of two numbers