Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In C, you need to specify the sizes of your arrays such as with <code>float nu[100];</code> but you're barking up the wrong tree if you think you need to store all those values. The minimum, maximum and sum can all be calculated on the fly without any need to go back and retrieve any previous numbers.</p> <p>All you need to do is enter them one at a time and, for each:</p> <ul> <li>if it's the first or greater the the current high, set the current high to it.</li> <li>if it's the first or less the the current low, set the current low to it.</li> <li>add it to a sum.</li> </ul> <p>The sum by the way, should be initialised to zero to start with.</p> <p>In terms of pseudo-code, start with this:</p> <pre><code>set sum, high and low all to zero scan "number of values" into count for curr = one to count, inclusive: scan "current number" into num set sum to sum + num if curr is one, or num is less than low: set low to num if curr is one, or num is greater than high: set high to num output "Minimum = " low output "Maximum = " high output "Sum = " sum </code></pre> <p>And the best way to understand it is to get a (very non-tech) piece of paper and write up a table like this:</p> <pre><code>+-----+------+-----+-----+-------+------+ | sum | high | low | num | count | curr | +-----+------+-----+-----+-------+------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----+------+-----+-----+-------+------+ </code></pre> <p>Then run that program step-by-step through your head, entering or changing the values in that table as you go. You'll even be able to detect when you're using uninitialised values such as if you came across <code>set sum to sum + curr</code> if the <code>sum</code> column was empty.</p> <p>You'll be surprised how quickly you begin to think like a computer, just hope it doesn't push all those social skills out of your head in the process :-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload