0% found this document useful (0 votes)
12 views5 pages

Programming Assignment Unit 7 Web Programming 1

The document contains programming assignments for a Web Programming course, focusing on PHP exercises. It includes code examples for adding integers between 0 and 50, checking voting eligibility based on age, and determining if a number is prime. Each program is accompanied by sample output and a reference link to an online PHP editor.

Uploaded by

munyendoadam9
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)
12 views5 pages

Programming Assignment Unit 7 Web Programming 1

The document contains programming assignments for a Web Programming course, focusing on PHP exercises. It includes code examples for adding integers between 0 and 50, checking voting eligibility based on age, and determining if a number is prime. Each program is accompanied by sample output and a reference link to an online PHP editor.

Uploaded by

munyendoadam9
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

Programming Assignment Unit 7

Bachelor of Computer Science


University of the People
CS 2205-01: Web Programming 1

Dr. Crystal Cummings


December 31, 2024
In this exercise, I used online PHP editor found in w3school.

1. Program to add all the integers between 0 and 50.

<?php

$total = 0; // Initialize total variable

// Use a for loop to add integers from 0 to 50

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

$total += $i; // Add current integer to total

// Display the total

echo "The total of integers between 0 and 50 is: " . $total;

?>

Output

1. Program to check if a person is eligible to vote

<?php

$age = 23; // Example age, you can change this value for testing
// Check if the person is eligible to vote

if ($age >= 18) {

echo "You are eligible to vote.";

} else {

echo "You are not eligible to vote.";

?>

Output

2. Program to check a number is prime or not.

<?php

$number = 39; // Example number, you can change this value for testing

$isPrime = true; // Assume the number is prime

// Check if the number is less than 2

if ($number < 2) {

$isPrime = false;
} else {

// Check for factors from 2 to the square root of the number

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

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

$isPrime = false; // Found a factor, so it's not prime

break;

// Display whether the number is prime or not

if ($isPrime) {

echo "$number is a prime number.";

} else {

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

?>

Output
Reference:

[Link]

You might also like