Ask Question
29 July, 14:24

Given the following segment of code,

/ / postcondition:returns x + y public int add (int x, int y) {}

/ / postcondition:return x * y public int multiply (int x, int y) {}

which of the following corresponds to this expression?

multiply (add (multiply (a, b), add (multiply (a, c), multiply (b, c))), 2)

1. a * b + a * c + b * c * 2

2. a * b + a * c + b * c + 2

3. a * b + (a * c + b * c)

4. (a * b + a * c + b * c) * 2

5.2 * a * b + (a * c + b * c)

+1
Answers (1)
  1. 29 July, 15:51
    0
    The whole line of code that performs an operation is this one:

    multiply (add (multiply (a, b), add (multiply (a, c), multiply (b, c))), 2)

    Let's do it step by step:

    Step 1: Perform the inner group of parenthesis. Then expand going out, until you reach the bigger parenthesis.

    Just bear in mind that multiply () = x * y

    and add () = x + y

    Last step: Get the final expression

    ((a * b) + (a*c + b*c)) * 2
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given the following segment of code, / / postcondition:returns x + y public int add (int x, int y) {} / / postcondition:return x * y public ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers