Question

2. (15 marks) Consider the following program: >> Precondition: x and y E Z. Postcondition: Return the sum x + y. add(x, y): 1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

add (x,y): ly return y 3) diy wo: return add (x-1, y ) + 1 3) else return add (2+1, y) - 1 This is a program for addition ofexample 1 , 4 = 3 add (2, 3) return 3 I add(0, 3) tik return 4 Ladd (1,3)+1 4+1 = 5 stuck at last will contain the result and4 is returned to its caller function that is add (1,3) Now It is Now so add (1, 3) = 4 Top of Stack - 4+1 = 5 the last uadueF 2) add (-1, 3) is called Te As a Lo so return It will get stored in stark add (-1+1, 3) -1 =) add (0,3)-1 3 add (0,3) is ca

Add a comment
Know the answer?
Add Answer to:
2. (15 marks) Consider the following program: >> Precondition: x and y E Z. Postcondition: Return...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT