25. Which of the following functions will keep accepting an input from a user un
ID: 3874624 • Letter: 2
Question
25. Which of the following functions will keep accepting an input from a user until the user types the value 5, at which point the function causes the message, Done, to be displayed and the function stops asking for input? You may assume that the user always enters a single numerical value. (a) function ilike5) flag = 1; while flag value - input('Enter a value :'); if value -5 disp('Done') flag = 0; end end (b) function ilike5) flag = 1; while flag >= 0 value - input('Enter a value:'); if value -5 disp('Done') flag = 0; end end (c) function ilike5) flag = 1; while flag value -input('Enter a value:); if value-= 5 disp('Done') flag = 0; end endExplanation / Answer
It is (b) because The condition to enter in while loop is '>=0' .After first execution the flag is given a zero and it will reenter the while loop because of '>=' condition because (0=0) so it will keep taking input until user enters '5' but this is not possible in (a)&( c) because there is condition '>0' so after the first execution or entering in while loop when the flag is assigned a zero value,program will not reenter in the while loop to ask for input because (0 is not >0).
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.