Write a programm in C to add two positive integers without using +sign.based on C programming

Expert Answers
thanatassa eNotes educator| Certified Educator

This exercise is designed to make you think in an original manner about algorithms. One possible solution is to first multiply both numbers by -1, and then subtract one number from the next number, and then multiply the result by -1 to convert the result back to a positive number. Thus, if the two numbers were X and Y, the result Z would be obtained by calculating:

Z = -1 * ((-1 * X) – (-1 * Y))

Although there are few cases where this specific algorithm would be useful, the type of thinking involved is really important for real time and machine language programming where you can often save machine cycles by forcing specific operations (e.g. shifting left rather than multiplying by 2).

Access hundreds of thousands of answers with a free trial.

Start Free Trial
Ask a Question