Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a complete PHP-enabled website using WebMatrix and choose either empty PH

ID: 3775246 • Letter: C

Question

Create a complete PHP-enabled website using WebMatrix and choose either empty PHP website or empty HTML website as the template. Rewrite the PHP code in Lab PHP 1 with two mandatory functions to print out first 10 prime numbers inclusively starting with 2. Print these numbers in one line and separate them with a coma and a space. The outer loop of PHP1 should be replaced with a function without return value, named printPrime($n1), to print out first n1 prime numbers starting with 2. printPrime($n2) must call another function with return value, named isPrime($n2), which determines if $n2 is a prime number. If yes, TRUE is returned, otherwise FLASE is returned. In the primary PHP script, call the printPrime($n1) function with appropriate actual parameter. Above two functions must be defined and called, otherwise 30 points penalty would be applied, 15 each.

Explanation / Answer

<?php

function IsPrime($n)

{

for($x=2; $x<$n; $x++)

{

if($n %$x ==0)

{

return 0;

}

}

return 1;

}

$a = IsPrime(3);

if ($a==0)

echo 'This is not a Prime Number.....'." ";

else

echo 'This is a Prime Number..'." ";

?>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote