The numbers are 3 and 4. 4 is the greater number
3 is odd
4 is even
3 is odd
4 is even
Code:
<html>
<head>
<title>PHP TEST YAHHH</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<div class="topbar">
<?php
include 'navbar.php';
?>
</div>
<?php
function findBigger ($a, $b) {
if ($a > $b) {
return ($a);
}
else if ($b > $a) {
return ($b);
}
else if ($b == $a) {
return ($a);
}
}
function evenOrOdd ($a) {
if ($a % 2 == 0) {
return true;
}
else {
return false;
}
}
$firstNumber = 3;
$secondNumber = 4;
$greaterNumber = findBigger($firstNumber, $secondNumber);
echo ("The numbers are $firstNumber and $secondNumber. $greaterNumber is the greater number");
echo '<br>';
if (evenOrOdd ($firstNumber) == true) {
echo ("$firstNumber is even");
echo '<br>';
}
else if (evenOrOdd ($firstNumber) == false) {
echo ("$firstNumber is odd");
echo '<br>';
}
if (evenOrOdd ($secondNumber) == true) {
echo ("$secondNumber is even");
echo '<br>';
}
else if (evenOrOdd ($secondNumber) == false) {
echo ("$secondNumber is odd");
echo '<br>';
}
//just to make the echo statements better, output result as even or odd instead of booleans
function evenOrOddMarkTwo ($a) {
if ($a % 2 == 0) {
return "even";
}
else {
return "odd";
}
}
echo '<br>';
echo '<br>';
echo ("$firstNumber is ");
echo evenOrOddMarkTwo ($firstNumber);
echo '<br>';
echo ("$secondNumber is ");
echo evenOrOddMarkTwo ($secondNumber);
echo '<br>';
/* outputs in this format:
The numbers are 3 and 4. 4 is the greater number
3 is odd
4 is even
3 is odd
4 is even
*/
?>
<div class="codebox">
<h3>Code:</h3>
<?php
highlight_file("ex012.php");
?>
</div>
</body>
</html>