Search code examples
pseudocode

Pseudo-code questions on setting values to a large minus or large positive number


In a program where you input 10 positive numbers and output the smallest number input, if I created a variable called "Small", why do I need to set that to a large positive number. In other programs, i've seen it being set up as a large minus number. Why is this?


Solution

  • I think what you mean by calling your variable 'small' is that you're gonna compare it to each input value and use it to store the smallest value then return it.

    But if the default value of your variable 'small' is already smaller than any input value then you will return a wrong result.

    You can either set it to an arbitrary large number or use the first value in your input set to avoid the problem.