PDA

View Full Version : Finding the smallest number?


fred22
10-05-2005, 12:54 AM
Anybody got any great ideas on how to find the smallest and biggest number in an array?

maybe...something like this....
float $array[] = {1,2,3};
float $min;
float $min2;
for($i=0; $i>size($array);$i++)
{
for($j=0; $j>size($array);$j++)
{
$min = `min $array[$i] $array[$j]`;
}
}
print $min;
print "\n";

Though I have the problem of reassigning the $min value with next comparasion minium value.

Thanks

harmless
10-05-2005, 01:26 AM
float $numAry[] = {32.1, 87.3, 1.1, -89.9, 1078.2};
float $sortedAry[] = `sort $numAry`;
int $count = size($sortedAry) - 1;
float $largest = $sortedAry[$count];
float $smallest = $sortedAry[0];


Cheers

fred22
10-05-2005, 01:50 AM
Thankyou soooo much!

CGTalk Moderation
10-05-2005, 01:50 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.