Wednesday 11 April 2012

Tutorial 4 - Question 3

Q3. Sometimes the meaning of what a programmer wrote isn’t what s/he intended. We then say the program has a logic error. Consider the following loop – if the programmer intended the loop to run 3 times, does it have a logic error? How many times will the loop run?

Answer:

  • Yes, It contain a logic error in above code. User want to loop 3 times.
    First error:-
  • index start from 5 up to (but not including) 2 times.
  • How the user want to loop 3 times, and it start from 5 and end in 2
    Second error:-
  • incrementing by 1 = (index + 1 )
    User should input (Decrementing by 1 = (index -1)

No comments:

Post a Comment