Question:

What's wrong with the program?

by  |  earlier

0 LIKES UnLike

Predict the output of the code if it is run on a binary computer that uses chopping. Estimate the # of times the programmer intended for this loop to be executed, and the number of times it is actually executed. Would the outcome be the same if "X=X+H" was replaced with "X=I*H" ?

I=0

X=0.0

H=0.1

WHILE X < 1.0

I = I + 1

X = X + H

disp([I,X])

end

 Tags:

   Report

1 ANSWERS




  1. Well, I think they want you to say it&#039;s an infinite loop. This is the correct codefor Matlab, run it and see what you get.  

    The programmer intended it to run until X &gt; 1.0, but in binary the number 1.0 is never TOTALLY equal to the number in base 10.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions