Homework Help

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

user profile pic

karthikgujjar | Student, Undergraduate | eNotes Newbie

Posted January 24, 2012 at 8:28 PM via web

dislike 0 like

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

based on C programming

1 Answer | Add Yours

user profile pic

thanatassa | College Teacher | (Level 2) Educator Emeritus

Posted January 25, 2012 at 3:26 AM (Answer #1)

dislike 1 like

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).

Sources:

Join to answer this question

Join a community of thousands of dedicated teachers and students.

Join eNotes