Answer Sheet
Answer Sheet
1. Enter the range and print all the numbers which is divisible by 5 or 10 [User Input ].
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Divisibility Check in Range</title>
</head>
<body>
<center>
<h3>Check Divisibility by 5 or 10 in a Range</h3>
<form action="" method="get">
<input type="number" name="start" placeholder="Start of Range"><br><br>
<input type="number" name="end" placeholder="End of Range"><br><br>
<button type="submit">Submit</button>
</form>
<?php
$start =$_GET['start'];
$end =$_GET['end'];
?>
</center>
</body>
</html>
2. Write a program in php and print the pattern using nested.
<?php
$rows = 5; // Number of rows
for ($i = $rows; $i >= 1; $i--) {
for ($j = 1; $j <= $i; $j++) {
echo "*"; // Print star
}
echo "<br>"; // Move to the next line after each row
}
?>
3. Write a program to check whether a given number is prime or not [user input].
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prime Number Checker</title>
</head>
<body>
<h1>Prime Number Checker</h1>
<form method="post">
<label for="number">Enter a number:</label>
<input type="text" id="number" name="number" required>
<button type="submit">Check Prime</button>
</form>
<?php
if (isset($_POST['number'])) {
$number = $_POST['number'];
$i = 2;
while ($i <= $number / 2) {
if ($number % $i == 0) {
echo "<h2>$number is not a prime number.</h2>";
return; // Exit immediately if a divisor is found
}
$i++;
}
echo "<h2>$number is a prime number.</h2>";
}
?>
</body>
</html>
4. Write a PHP script to check if a person is eligible to vote (age >= 18).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head><center>
<body>
<form method="GET">
Enter your Age: <input type="number" name="num" >
<button type="submit" >Calculate The Age Of A Voter</mark> </button>
</form>
<?php
$age=$_GET['num'];
if($age>=18){
echo "$age is a eligible for vote";
}else{
echo "$age is not eligible for vote";
}
?>
</center>
</body>
</html>
5. Write a PHP program to swap two numbers using a third variable.
<?php
// Define two variable
$num1 = 10;
$num2 = 20;
// Display results
echo "Addition: $num1 + $num2 = $sum\n";
echo "Subtraction: $num1 - $num2 = $difference\n";
echo "Multiplication: $num1 * $num2 = $ multiply \n";
echo "Division: $num1 / $num2 = $division\n";
?>