Using WebMatrix or equivalent IDE, create a website made of one HTML file and on
ID: 3714553 • Letter: U
Question
Using WebMatrix or equivalent IDE, create a website made of one HTML file and one PHP file. Do not create a pure PHP file without HTML code, i.e. add HTML code to the file. In the HTML file, create one textboxes with label and read a positive integer n from the user. Add a "Submit" button below the textbox.
The PHP file should have at least two functions isPrime() and printPrime(). The isPrime(n) function judges if n is a prime number and returns true when n is a prime. The printPrime(n) should return the first n prime number in ascending order starting from 2. The major script in the PHP file first receives the input integer from above HTML file then calls function printPrime(n) with this number as the parameter.
Explanation / Answer
Firstly, create a html file and write below code. Save it with the name "firsthtml.html".
// HTML File Code.
<html>
<head>
</head>
<body>
<label for="num">Enter Number</label>
<input type="text" name="num" id="num" value="">
<input type="submit" value="submit" name="submit">
</body>
</html>
// Then, Create a php file with name "firstproject.php" and write below code in it. Then Run it.
<?php
include 'firsthtml.php'; // To include html file
if(isset($_POST['submit']) && !empty($_POST['submit'])) {
{
$a = $_POST['num'];
$a = 53;
if($a != '')
{
$b = isPrime($a);
if($b == 1)
{
echo "Given number is a prime Number ";
}
else
{
echo "Given number is NOT a prime Number ";
}
printPrime($a);
}
}
function isPrime($num) // funtion to check if a number is prime or not.
{
if($num == 0)
return 0;
for($i=2;$i<=$num/2;$i++)
{
if($num%$i == 0)
return 0;
}
return 1;
}
function printPrime($num) // function to print all the prime number in ascending order less than n
{
echo "The first n prime number are : ";
for($i=2;$i<=$num;$i++)
{
if(isPrime($i))
{
echo $i." ";
}
}
echo " ";
}
?>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.