Write a php page that will ask the user to enter a number on a text box and then
ID: 3548640 • Letter: W
Question
Write a php page that will ask the user to enter a number on a text box and then output a
message to indicate if the number is even or odd
Modify the above, in addition to output if the number is even or odd, output if the number is a
prime number.
i have this code for even or odd. but i need it to be able to ask the user to enter the number in textbox. can you help me with the code i currently have to get this working!
Even or odd:
$number = 20;
if ($number % 2 == 0) {
print "It's even";
}
PRIME:
function isPrime($num) {
//1 is not prime. See: http://en.wikipedia.org/wiki/Prime_number#Primality_of_one
if($num == 1)
return false;
if($num == 2)
return true;
if($num % 2 == 0) {
return false;
}
for($i = 3; $i <= ceil(sqrt($num)); $i = $i + 2) {
if($num % $i == 0)
return false;
}
return true;
}
Explanation / Answer
Input file
<?php>
echo "Enter a number: <input type="number" name="number">";
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.