Question: Question 1 : Assume that the above function is defined in the current directory. The following code is then run in the Command Window: `

Question 1:
Assume that the above function is defined in the current directory. The following code is then run in the Command Window:
```
arr =[20; 31; 25; 48];
[new1,max1]= bestSum(arr)
```
After the function is run, what will be the values of new1 and max1?
Question 2:
Using the same input given in question 1, how many TOTAL times will the for loop on lines 6-8 run?
Question 3:
Suppose that Line 10 is uncommented. Does the for loop now operate different? If you believe it operates differently, what will the values of temp and newArr be once the code reaches line 12.(In other words, after the loop from 4-11 is done)```
function [newArr, maxSum]= bestSum(arr)
[r,c]= size(arr);
newArr =[];
fori =1:c
temp =0;
for j =1:r
temp = temp + arr(j, i);
end
newArr =[newArr temp];
% i = i +1;
end
ind =2;
maxSum = newArr(1);
while ind = length(newArr)
if newArr(ind)> maxSum
maxSum = newArr(ind);
end
ind = ind +1;
end
end
```
Question 1 : Assume that the above function is

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!