Ask Question

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. 10 September, 05:09
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers