ENGR 2304 IN-CLASS FINAL EXAM December 13, 2017 Frst Problem 1. Write the screen
ID: 2266419 • Letter: E
Question
ENGR 2304 IN-CLASS FINAL EXAM December 13, 2017 Frst Problem 1. Write the screen dispsy for the following script and assoc iated Sunction in tie space provided. For this question assume each outpu is put on one ine and there are no blank lines between the ouputs. You may not need all the lines provided (25 points) Credit only given for work shown Dis a-11 -2 20 -3 3 b-1-12-3 n-b (n while end dispf 'bye bye' function tm,n]confusel im,n, a,b) if m>4 disp( Branch 1) 10 temp=a (n-1) *b (n+1) ; disp('temp") elseif (nExplanation / Answer
Solution :
1)
close all;
clear all;
clc;
disp('Begin problem 1');
a = [1 -2 2 0 -3 3 4];
b = [-1 2 -3 4 -5 6 -1];
c=0;
n=7;
m=b(n);
while n>=0
[m,n]=confuse1(m,n,a,b);
c=c+1;
end
disp(['Number of loops is ',num2str(c)]);
disp('bye bye')
function [m,n] = confuse1(m,n,a,b)
if m>4
disp('Branch 1')
temp = a(n-1)*b(n+1);
n = n-5;
disp('temp');
elseif (n<=2 | n==4)
disp('Branch 2')
m=m+6;
temp=a(n+1)*b(m-1);
disp(temp);
else
disp('Branch 3')
temp=a(n)*b(m+3);
n=abs(n-3);
disp(temp);
end
%************************This gives output :
2)
close all;
clear all;
clc;
message1 = 'eating good';
message2 = 'makes studying satisfying';
total = [message1,' food ',message2];
s1 = ['Be ',message1(8:11)];
s2 = '';
for i=[7,8,2,11]
s2 = [s2 ,message2(i)];
end
s3 = [message2(16:17),message2(21),message2(4)];
disp(total)
disp(s1)
disp([s2 ,' ',s3])
%**************************
The output is :
eating good food makes studying satisfying
Be good
stay safe
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.