Faulty Key

Ninja is trying to write a function that takes two integers and returns their sum. But, due to some faults in his keyboard, he can not use the “+”, operator, which means he is not able to simply return ‘A’ + ‘B’, where ‘A’ and 'B' are the numbers to be added. You need to help Ninja in finding the sum of two numbers without using the "+" operator anywhere in your code.

Note:
 You should also not use the increment "++" operator too.
For example :
You are given A = 4, B = 6, their sum = 10, you need to return 10.
Input Format:
The first line contains an integer ‘T’ which denotes the number of test cases or queries to be run. Then the test cases are as follows.

The first and only line of each test case contains two space-separated integers denoting ‘A’ and ‘B’ respectively.
Output Format:
For each test case, print the sum of the two numbers without using the “+” operator.

Print the output of each test case in a separate line.
Note:
You don’t need to print anything; It has already been taken care of.
Constraints:
1 <= T <= 100
-10000 <= A, B <= 10000

where ‘T’ is the number of test cases and ‘A’ and ‘B’ are the two integers.

Time limit: 1 sec
CodingNinjas
author
2y
Using a subtraction operator.

This is a very basic approach. In this approach, we will be simply subtracting the negative of the second number from the first number.

  • For example: A = 4, B = 6
  • Now, negati...read more
CodingNinjas
author
2y
Extending the Half Adder logic

In this approach, we will use the logic behind the half adder that is used to find the sum of single bits and extend it so that we could add integers.

  • We will start with...read more
Help your peers!
Add answer anonymously...
INCA INFOTECH TECHNOLOGIES Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter