Laboratory No: Name of Subject Teacher: Sneha Patange
Name of Student: Harshraj Mandhare Roll Id: 21203A0062
Experiment No: 2
Title of Write a PHP program to demonstrate the use of Decision-making
Experiment control structures using a. If statement b. If-else statement c. Switch statement
Name of Program Program Output
Write a script to check <?php 7 is odd number
whether the number is if ($number%2==0) even or odd. { echo $number,”is even number”; } else { echo $number,”is odd number”; } $number=7; ?>
Write a script to find <?php b is greater than a
largest of 2 numbers. $a=7; $b=23; if($a>$b) { echo “a is greater than b”; } else { echo “b is greater than a”; } ?>
Write a script to display <?php b is greater than a
largest of 3 numbers using $a=7; and c nested if-else. $b=23; $c=17; if($a>$b) { if($a>$c) { echo “a is greater than b and c”; } else { if($c>$b) { echo “c is greater than a and b”; } } } else { echo “b is greater than a and c”; } ?>
Write a script to display <?php 23 is the largest
largest of 3 numbers using $a=7; number ternary operator $b=23; $c=17; $largest=($a>$b)?(($a>$c)?$a:$c): (($b>$c)?$b:$c); Echo $largest,” is the largest number”; ?>
Write a script to display <?php First Class
test result of a student $marks=70; using else-if ladder. if($marks>=75) Eg… { echo Greater than equal to 75 “Distinction”; marks = Distinction 74 } to 60 marks = First else if($marks>=60 and $marks<=74) class { echo “First 59 to 40 marks = Second Class”; class Less than 39 marks = Fail } else if($marks>=40 and $marks<=59) { echo “Second Class”; } else echo “Fail”; } ?>
Write a script to display <?php Distinction
test result of a student $marks=77; using switch case. switch($marks) Eg… { case Greater than equal to 75 $marks>=75: marks = Distinction 74 echo “Distinction”; break; case to 60 marks = First $marks>=60 and $marks<=74: class echo “First Class”; break; case 59 to 40 marks = Second $marks>=40 and $marks<=59: class echo “Second Class”; Less than 39 marks = Fail break; default: echo “Fail”; break; } ?>