Computer Science ( Only third question ) Question 2. a. Let the function fun be defined as int fun(int *k) { *k += 4; return 3 * (*k) - 1; Suppose fun is used in a program as follows: void main(O{ int...


Computer Science<br>( Only third question )<br>Question 2.<br>a. Let the function fun be defined as<br>int fun(int *k) {<br>*k += 4;<br>return 3 * (*k) - 1;<br>Suppose fun is used in a program as follows:<br>void main(O{<br>int i = 10, j = 10, suml, sum2;<br>suml = (i / 2) + fun (&i);<br>sum2 = fun (&j) + (j / 2);<br>}<br>What are the values of sum1 and sum2 in the following two cases?<br>1) If the operands in the expression are evaluated<br>left to right<br>2) If the operands in the expression are evaluated<br>right to left<br>sum1 = (inew / 2) + fun(&iold)<br>= 14 / 2 + (3 * (10 + 4) 1)<br>sum1 = (iold / 2) + fun(&iold)<br>= (10 / 2) + (3 * (10 + 4) 1)<br>= 5+ 41<br>= 46<br>sum2 = fun(&jold) + (įnew / 2)<br>= (3 * (10 + 4) – 1) + (14 / 2)<br>= 7+41<br>= 48<br>sum2 = fun(&jold) + (jold / 2)<br>= (3 * (10 + 4) – 1) + (10 / 2)<br>= 41 +7<br>= 41 +5<br>= 48<br>= 46<br>Question 3:<br>Rewrite the program in Question 2 part a in Java and C#, run them, and compare the<br>results.<br>

Extracted text: Computer Science ( Only third question ) Question 2. a. Let the function fun be defined as int fun(int *k) { *k += 4; return 3 * (*k) - 1; Suppose fun is used in a program as follows: void main(O{ int i = 10, j = 10, suml, sum2; suml = (i / 2) + fun (&i); sum2 = fun (&j) + (j / 2); } What are the values of sum1 and sum2 in the following two cases? 1) If the operands in the expression are evaluated left to right 2) If the operands in the expression are evaluated right to left sum1 = (inew / 2) + fun(&iold) = 14 / 2 + (3 * (10 + 4) 1) sum1 = (iold / 2) + fun(&iold) = (10 / 2) + (3 * (10 + 4) 1) = 5+ 41 = 46 sum2 = fun(&jold) + (įnew / 2) = (3 * (10 + 4) – 1) + (14 / 2) = 7+41 = 48 sum2 = fun(&jold) + (jold / 2) = (3 * (10 + 4) – 1) + (10 / 2) = 41 +7 = 41 +5 = 48 = 46 Question 3: Rewrite the program in Question 2 part a in Java and C#, run them, and compare the results.

Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here