0% found this document useful (0 votes)
10 views4 pages

Web Programming 7

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Web Programming 7

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

<?php

$sum = 0;

for ($i = 0; $i <= 50; $i++) {

$sum += $i;

echo "The sum of all integers between 0 and 50 is: $sum \n";

?>

2.

<?php

function checkVotingEligibility($age) {

if ($age >= 18) {

echo "You are eligible to vote!\n";

} else {

echo "You must be at least 18 years old!\n";


}

checkVotingEligibility(20);

checkVotingEligibility(10);

?>

3.

<?php

function isPrime($number) {

if ($number < 2) {

return false;

for ($i = 2; $i <= sqrt($number); $i++) {

if ($number % $i == 0) {

return false;

}
}

return true;

$input = readline("Enter a number: ");

if (is_numeric($input)) {

$number = (int)$input;

if (isPrime($number)) {

echo "$number is a prime number.\n";

} else {

echo "$number is not a prime number.\n";

} else {

echo "Please enter a valid number.\n";

?>
Reference

W3schools. (n.d.). PHP Tutorial.

[Link]

You might also like