Find largest and smallest number from 100,205,345,465,565,696,777,869,999
Program:
<?php
$numbers = array(100,205,345,465,565,696,777,869,999);
// Find the largest number
$largest = $numbers[0];
foreach ($numbers as $num) {
if ($num > $largest) {
$largest = $num;
}
}
// Find the smallest number
$smallest = $numbers[0];
foreach ($numbers as $num) {
if ($num < $smallest) {
$smallest = $num;
}
}
echo "The largest number is: " . $largest . "\n";
echo "The smallest number is: " . $smallest;
?>
$numbers = array(100,205,345,465,565,696,777,869,999);
// Find the largest number
$largest = $numbers[0];
foreach ($numbers as $num) {
if ($num > $largest) {
$largest = $num;
}
}
// Find the smallest number
$smallest = $numbers[0];
foreach ($numbers as $num) {
if ($num < $smallest) {
$smallest = $num;
}
}
echo "The largest number is: " . $largest . "\n";
echo "The smallest number is: " . $smallest;
?>
Output:
Find largest and smallest number from 1,2,3,4,5,6,7,8,9
Program:
<?php
$numbers = array(1,2,3,4,5,6,7,8,9);
// Find the largest number
$largest = $numbers[0];
foreach ($numbers as $num) {
if ($num > $largest) {
$largest = $num;
}
}
// Find the smallest number
$smallest = $numbers[0];
foreach ($numbers as $num) {
if ($num < $smallest) {
$smallest = $num;
}
}
echo "The largest number is: " . $largest . "\n";
echo "The smallest number is: " . $smallest;
?>
$numbers = array(1,2,3,4,5,6,7,8,9);
// Find the largest number
$largest = $numbers[0];
foreach ($numbers as $num) {
if ($num > $largest) {
$largest = $num;
}
}
// Find the smallest number
$smallest = $numbers[0];
foreach ($numbers as $num) {
if ($num < $smallest) {
$smallest = $num;
}
}
echo "The largest number is: " . $largest . "\n";
echo "The smallest number is: " . $smallest;
?>
Output:
The largest number is: 9
The smallest number is: 1