Here's a way to do it in pseudo-code:
And that's it. You may notice that this algorithm will work no matter how many of the largest numbers you're looking for. Here's an example of how to do it in PHP:
function getBiggest($values, $quantity){
if(!is_array($values)) return $values;
$highvalues = array();
foreach($values as $value){
for($n = 0; $n < count($highvalues); $n++){
if($value > $highvalues[$n]){
$v = $value;
$value = $highvalues[$n];
$highvalues[$n] = $v;
}
}
if($n < $quantity) $highvalues[$n] = $value;
}
return $highvalues;
}
Two numbers: the first of them is 1 and the second is not!Two numbers: the first of them is 1 and the second is not!Two numbers: the first of them is 1 and the second is not!Two numbers: the first of them is 1 and the second is not!
1.Start Algorithm 2.Enter first number 3.Enter second number 4.Enter third number 5.Enter fourth number 6.Enter fifth number 7.Add five number 8.display five number / 2 9.Display result 10.End Algorithm
Multiply the first fraction by the reciprocal of the second. That is, flip the second fraction over and then multiply the two.
Russia is first, followed by Canada.
A "first fit" algorithm is any algorithm which doesn't care about how "good" a solution is, it just returns the first one that works.
The following algorithm works for any number of integers: Assume the first number is the maximum - maximum = (first number). Compare your assumed maximum with the second number. If the second number is larger than the assumed maximum, replace the old assumed maximum with the second number. Repeat for the third number, for the fourth, etc. - always copying the nth. element to the assumed maximum if you find one that is larger than your previous maximum.
Two numbers are consecutive if the second one is the one after the first. Mathematically, if the first number is n then the second is n+1.
Ada Lovelace described and published an algorithm for Charles Babbage's analytical engine to computer Bernoulli numbers. It is generally considered the first algorithm ever specifically tailored for implementation on a computer, and for this reason she is considered by many to be the first computer programmer.
= The sum of two numbers is -42 the first number minus the second number is 52 Find the numbers? =
No. It's third in population. California is first and Texas is second.
If you use methods based on prime factors, it is the same whether you have 2, 3, or more numbers: find all the factors that occur in any of your numbers. If you use a method based on Euclid's Algorithm (that is, lcm(a, b) = a x b / gcf(a, b), where you find the gcf with Euclid's Algorithm), then you can find the lcm for two numbers at a time. For example, to get the lcm of four numbers, find the lcm of the first two, then the lcm of the result and the third number, than the lcm of the result and the fourth number.
First is Timber Second is Wheat and third is oil