Writing Shit
Writing Shit
2.
<?php
echo"<h1> Practical 1</h1>";
echo"Welcome to PHP";
echo"<br>";
echo"Performed By Muskan"
?>
3.
<html>
<title>Arithmetic Operations</title>
<body>
<center>
<h1>
<b>
<?php
echo("EXPERIMENT 1");
echo("<br>Arithmetic Operations");
echo("<br>Performed by: MUSKAN KATEJA");
// Predefined values
$num1 = 2; // First number
$num2 = 10; // Second number
// Display results
echo "<h2>Results:</h2>";
echo "Addition: $num1 + $num2 = $addition<br>";
echo "Subtraction: $num1 - $num2 = $subtraction<br>";
echo "Multiplication: $num1 * $num2 = $multiplication<br>";
echo "Division: $num1 / $num2 = $division<br>";
?>
</b>
</h1>
</center>
</body>
</html>
Exercise
2.
1. Arithmetic Operators
<?php
$a = 10;
$b = 5;
echo "Addition: " . ($a + $b); // Output: 15
echo "Multiplication: " . ($a * $b); // Output: 50
?>
2. Comparison Operators
Used to compare two values.
Example:
<?php
$x = 20;
$y = 15;
echo ($x > $y) ? "x is greater than y" : "x is not greater than y";
// Output: x is greater than y
?>
Exp 2
20
<!DOCTYPE html>
<html>
<head>
<title>Even or Odd Checker</title>
<style>
body {
text-align: center;
}
</style>
</head>
<body>
<h1>Even or Odd Checker</h1>
<?php
$number = 5;
if ($number % 2 == 0) {
echo "<p>$number is even.</p>";
} else {
echo "<p>$number is odd.</p>";
}
?>
<p>Developed by Zeal Gala</p>
</body>
</html>
Page 22 Q1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Check Number</title>
</head>
<body>
<?php
$number = -5; // Change this value to test different numbers
<div>
<p>Developed by Muskan Kateja</p>
</div>
</body>
</html>
22 Q2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Check Number</title>
</head>
<body>
<?php
$number = -5; // Change this value to test different numbers
// Check if the number is positive, negative, or zero
if ($number > 0) {
echo "<p>The number <strong>$number</strong> is positive.</p>";
} elseif ($number < 0) {
echo "<p>The number <strong>$number</strong> is negative.</p>";
} else {
echo "<p>The number is zero.</p>";
}
?>
<div>
<p>Developed by Zeal Gala</p>
</div>
</body>
</html>
22 q3
<!DOCTYPE html>
<html>
<head>
<title>Day Finder</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Day Finder</h1>
<?php
$mon = date('N');
switch ($mon){
case '1':
echo "Today is Monday";
break;
case '2':
echo "Today is Tuesday";
break;
case '3':
echo "Today is Wednesday";
break;
case '4':
echo "Today is Thursday";
break;
case '5':
echo "Today is Friday";
break;
case '6':
echo "Today is Saturday";
break;
case '7':
echo "Today is Sunday";
break;
default:
echo "Not a valid Day";
break;
}
?>
PRQ
● Comparison Operators:
○ == (equal to)
○ != (not equal to)
○ > (greater than)
○ < (less than)
○ >= (greater than or equal to)
○ <= (less than or equal to)
● Logical Operators:
○ && (logical AND)
○ || (logical OR)
○ ! (logical NOT)
2. In if-else construct which part will be executed if condition is true.
Example:
<?php
$age = 18;
if ($age >= 18) {
echo "You are an adult."; // This will execute as the condition is true.
} else {
echo "You are a minor.";
}
?>
3. State the condition when the else part will be executed with example.
The else part will be executed when the condition in the if statement is false.
Example:
<?php
$age = 15;
if ($age >= 18) {
echo "You are an adult.";
} else {
echo "You are a minor."; // This will execute as the condition is false.
}
?>
Exp 3
Page - 27
<!DOCTYPE html>
<html>
<head>
<title>First 30 Even Numbers</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>First 30 Even Numbers</h1>
Page - 29
1.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Factorial Experiment</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<?php
function calculateFactorial($number) {
$factorial = 1;
if ($number < 0) {
return "Factorial is not defined for negative numbers.";
} else {
for ($i = 1; $i <= $number; $i++) {
$factorial *= $i;
}
return $factorial;
}
}
for ($i = 1; $i <= 5; $i++) {
echo "<p class='factorial'>The factorial of $i is " . calculateFactorial($i) . "</p>";
}
?>
<p class="developer">Developed by Mohit Gurnani</p>
</body>
</html>
2.
2.1 (star wala)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Star Pattern Experiment (Incrementing)</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<?php
// Program to print an incrementing pyramid of stars (left aligned)
echo "<div class='pattern'>";
for ($i = 1; $i <= 5; $i++) {
for ($j = 1; $j <= $i; $j++) {
echo "* "; // Print stars for incrementing pattern
}
echo "<br>";
}
echo "</div>";
?>
</body>
</html>
2.2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Number Pattern Experiment (Decrementing)</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<?php
// Program to print a decrementing pyramid of numbers (left aligned)
echo "<div class='pattern'>";
for ($i = 5; $i >= 1; $i--) {
for ($j = 1; $j <= $i; $j++) {
echo "$i "; // Print numbers for decrementing pattern
}
echo "<br>";
}
echo "</div>";
?>
<p class="developer">Developed by Muskan Kateja</p>
</body>
</html>
PRQ
● A for loop terminates when the loop condition becomes false. The loop runs as long
as the specified condition evaluates to true.
● The termination occurs after completing one iteration of the loop if the condition is no
longer met.
Example:
php
CopyEdit
<?php
for ($i = 0; $i < 5; $i++) {
echo $i; // This will print 0 to 4
}
?>
In the above example, the loop will terminate when $i becomes 5 because the condition $i <
5 will then be false.