Q. For some calculations, we want an algorithm that accepts only positive integers upto 100.


Accept_1to100_Algo

INPUT Number

IF (0<= Number) AND (Number <= 100)

   ACCEPT

Else

   REJECT


a) On what values will this algorithm fail?

b) Can you improve the algorithm?


Answer :-

If we enter 0 then this algorithm will fail.

Correct algorithm :-

INPUT Number
IF (0< Number) AND (Number <= 100)
   ACCEPT
   Else
      REJECT

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post