What value will be displayed at the end of the

This preview shows page 5 - 7 out of 8 pages.

Q2. What value will be displayed at the end of the execution of the following script: res = east(west(2,6)); disp(res); where the function east is defined as function x = east(a) x = 2*a - 1; end and the function west is defined as function l = west(l,m) l = [l m]; end Q3. What value will be displayed at the end of the execution of the following script: burger = 2; bball = 1; when = 4; energy = 13; lumslife = eat(burger) + play(bball, when) + sleep(); disp(lumslife); where the function play is defined as function [energy winloss] = play(game,tme,eng) energy = -game*tme; if energy > 7 winloss = 1; else winloss = 0; end end and the function eat is defined as function energy = eat(food) energy = food; end and the function sleep is defined as function [en] = sleep() en = 5; end P.T.O 2 0 - - Answer box for Qs 1 Answer box for Qs 2 Answer box for Qs 3
Image of page 5

Subscribe to view the full document.

Q4. What value will be displayed at the end of the execution of the following script: [e w]= playAgain (2,4,25); disp(e-w); where the function playAgain is defined as function [energy winloss] = playAgain(game,tme,eng) energy = eng -game*tme; if energy > 12 [energy winloss]= playAgain(game,tme,energy); else winloss = 1; end end Q5. What value will be displayed at the end of the execution of the following script: x = [ 3 2 1 4 8 11 3 8]; x = foo(x(1:end/2), x(end/2+1:end)); disp(x); where the function foo is defined as function y = foo(a,b) y = b(a); end Q6. What is the value of x at the end of the execution of the following script: x = [ 1 0 4 3 6 5 7 4]; x = newx(x); x = [x(end:-1:4) x]; where the function newx is defined as function y = newx(x) y = []; for i=2:size(x,2) if x(i) < x(i-1) y = [y x(i)]; end end end Answer box for Qs 5 Answer box for Qs 6 Answer box for Qs 4
Image of page 6
CS100 Quiz Roll Number Nov 29, 2012 Q1. What value will be displayed at the end of the execution of the following script: x = 2; y = 3; a = 5; b = 4; [y a] = fan(b,x); disp(y+b); where the function fan is defined as function [a b] = fan(a, b) a = a + 1; b = b + a; end Q2. What value will be displayed at the end of the execution of the following script: res = east(west(7,2)); disp(res); where the function east is defined as function x = east(a) x = 2*a - 1; end and the function west is defined as function l = west(l,m) l = [l m]; end Q3. What value will be displayed at the end of the execution of the following script:
Image of page 7
You've reached the end of this preview.
  • Spring '13
  • SaraScott
  • WinLoss, function fan

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern