Programs
Programs
Assignment 2
1. Write a program to check whether the person is adult or not.
3. Write a program to show day of the week (for example: Monday) based on
numbers using switch/case statements.
Conditions:
You can pass 1 to 7 number in switch
Day 1 will be considered as Monday
If number is not between 1 to 7, show invalid number in default
Assignment 3
1. Write a program to print “TCET” 5 times using do while loop
2. Write a factorial program using for loop in php
3. Write a Program to create given pattern with * using for loop
4. Write a program to print all even numbers between 1 to 10 using while loop
5. Write a program to print all odd numbers between 1 to 10 using while loop
If statement
<!DOCTYPE html>
<html>
<body>
<?php
$num=12;
if($num<100){
echo "$num is less than 100";
}
?>
</body>
</html>
If else Statement
<!DOCTYPE html>
<html>
<body
<?php
$num=12;
if($num%2==0){
echo "$num is even number";
}else{
echo "$num is odd number";
}
?>
</body>
</html>
If else if statement
<!DOCTYPE html>
<html>
<body>
<?php
$marks=69;
if ($marks<33){
echo "fail";
}
else if ($marks>=34 && $marks<50) {
echo "D grade";
}
else if ($marks>=50 && $marks<65) {
echo "C grade";
}
else if ($marks>=65 && $marks<80) {
echo "B grade";
}
else if ($marks>=80 && $marks<90) {
echo "A grade";
}
else if ($marks>=90 && $marks<100) {
echo "A+ grade";
}
else {
echo "Invalid input";
}
?>
</body>
</html>
Nested IF
<!DOCTYPE html>
<html>
<body>
<?php
$age = 23;
$nationality = "Indian";
//applying conditions on nationality and age
if ($nationality == "Indian")
{
if ($age >= 18) {
echo "Eligible to give vote";
}
else {
echo "Not eligible to give vote";
}
}
?>
</body>
</html>