Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

SW1 SW2 SW3 Light Bulb 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 1 1

ID: 3565023 • Letter: S

Question

SW1

SW2

SW3

Light Bulb

0

0

0

0

0

0

1

1

0

1

0

0

0

1

1

1

1

0

0

0

1

0

1

1

1

1

0

1

1

1

1

1

Ask the user for the state of each switch. (1 for on and 0 for off) and then return the corresponding state of the light bulb. Create an anonymous function (accepting 3 inputs) where you use logical operators to determine and return the state of the light bulb. From the script file, display the state with fprintf.

(Hint: DO NOT over complicate this task. No

SW1

SW2

SW3

Light Bulb

0

0

0

0

0

0

1

1

0

1

0

0

0

1

1

1

1

0

0

0

1

0

1

1

1

1

0

1

1

1

1

1

Explanation / Answer

A= input('please enter the SW1 ');
B= input('please enter the SW2 ');

C= input('please enter the SW3 ');
light= @(A,B,C) (~A)*(~B)*(C)+(~A)*B*C+(A)*(~B)*C+(A)*(B)*(~C)+A*B*C;
K= light(A,B,C);
i=1;
while K*(i)
fprintf(' bulb will be on');
i=i-1;
end
while (~K)*i
fprintf(' light bulb will be off ');
i=i-1;
end