How to find the greatest of numbers

How to find the greatest of numbers

If it is necessary to learn the greatest number in any sequence of numbers, it is possible to make it, for example, by means of the software installed in your computer. And if the procedure of stay has to be embodied in any programming language, it is necessary to make an algorithm and to realize it the means available in concrete language.

Instruction

1. For finding of the greatest number in the set set it is possible to use, for example, the tabular editor of Microsoft Office of Excel. Having started it, enter set numbers into the next cells of the table - across or down, it does not matter. If the total number of rooms is big and it is manually difficult to enter it, then it is possible to try to make it method of copying and an insert.

2. Place in the first free cell after a column (or lines) with numbers function of finding of the greatest number. For this purpose click this cell and press the pictogram "To insert function", placed at the beginning of "a line of formulas" over the table. Excel will be started by "The master of functions" in whom to you it is necessary to choose in a drop-down list "Category" "Statistical", and then in the list of functions to click the line "MAKS" and to press the OK button. In the following window the master of functions himself will allocate all range of the numerical values entered by you in which it is necessary to carry out search. Press the OK button and you will see the greatest number of the entered sequence.

3. If it is necessary to find the greatest number of a set means of any programming language, then the algorithm can be, for example, such: at first appropriate to a variable resultant value of the first of a set. Then consistently touch set numbers, comparing them to a variable resultant. If this number is more, then appropriate its value to a variable resultant. For example, in the PHP language it can look so: $arr = array(15, 18, 92, 56, 92); $max = $arr [0]; foreach ($arr as of $val) if ($val> of $max) $max = $val; $max echo;

4. However in the majority of languages there are built-in functions or for search in the massif of the maximum value, or for sorting of the massif according to increase or decrease. Therefore to organize such cycles of calculations there is no need, it is simpler to use the built-in functions. For example, in the PHP language the code provided in the previous step can be replaced with it: $arr = array(15, 18, 92, 56, 92); rsort ($arr); echo of $arr [0]; Here function of sorting of the massif from the maximum value to minimum (rsort) is used. As a result of its work the very first element of the massif ($arr [0]) will contain value of the greatest number in the massif.

Author: «MirrorInfo» Dream Team


Print