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

Write a program that asks a user to enter a value between 0 and 10. If the enter

ID: 3936384 • Letter: W

Question

Write a program that asks a user to enter a value between 0 and 10. If the entered value is beyond these bounds, the program asks the user to enter the value again. If the entered value is between 0 and 10, your script divides the value into half again and again, until the value reaches a very small value (0.001 or less). If the user enters 4, for example, the value becomes 2, 1, 0.5, 0.25, and so forth. Let the program display these intermediate values. The program repeals this division to make the value successively smaller. The program stops calculation once the value reaches 0.001 or less. Completing this calculation, your script responds "For the entered value of X, division was repeated Y times." Of course, instead of X and Y. your program shows the actual values. Run your script for three different eases: -5, 5, and 15. Submission: 1 m-file and a printout of the command window.

Explanation / Answer

n=input('enter a value between 0 and 10 ');

flag=1

if(!(n>=0&&n<=10))

flag=0

end

while(flag==0)

{

n=input('enter a value between 0 and 10 ');

if(!(n>=0&&n<=10))

flag=0

else

flag=1

end

end

count=0

m=n

while(n>0.001)

fprintf("%f division by 2 = %lf",n,n/2)

n=n/2;

count=count+1

end

fprintf("for the entered value of %f divisiin by 2 was repeated %d times to reach %lf ",m,count,n)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote