S.
NO DATE NAME OF THE PROGRAM PAGE SIGNATU
NO. RE
DATA STRUCTURES AND ALGORITHM LAB
1. 12.01.24 SUM OF DIGITS 1
FACTORIAL OF A GIVEN NUMBER USING
2. 19.01.24 FUNCTION 3
PALINDROME OR NOT USING FORMS
3. 23.01.24 6
4. 23.01.24 BIGGEST NUMBER USING FUNCTION 8
DISPLAY BOOK DETAILS USING FOREACH
5. 05.02.24 LOOP 10
6. 06.02.24 REVERSE THE DIGIT 12
7. 07.02.24 STUDENT MARK LIST 15
8. 09.02.24 GET INPUT FROM CLIENT PAGE AND 19
PERFORM ARITHMETIC OPERATION
9. 09.02.24 DISPLAY HE/SHE ELIGIBLE FOR VOTE OR 22
NOT IN SERVER PAGE
10. 15.02.24 PERFORM STRING MANIPULATION AND 24
DISPLAY IN SERVER PAGE
EX.NO.1 SUM OF
DIGITS. DATE :
AIM :
To write a PHP program to Perform sum of digits using forms.
PROGRAM:
<html>
<head>
<title> sum of digits </title>
</head>
<body>
<form method="post">
<input type="text" name="number">
<input type="submit" name="submit">
</form>
<?php
if(isset($_POST['submit']))
{
$n=$_POST['number'];
$sum=0;
while($n>0)
{
$r=$n%10;
$sum=$sum+$r;
$n=$n/10;
}
echo"sum of digits is=".$sum;
}
?>
</body>
</html>
1
OUTPUT:
RESULT:
Thus the above program was successfully executed and verified.
2
EX.NO:2 FACTORIAL OF A GIVEN NUMBER USING
FUNCTION DATE :
AIM :
To write a PHP program to Perform Factorial of a given number using function
PROGRAM:
<html>
<body >
<form action=fact2.php method="post">
Enter Factorial Number<input type="text" name="t1"><br>
<input type="submit" value="Submit"><br>
<?php
function Factorial($number)
if($number <= 1)
return 1;
else
return $number * Factorial($number - 1);
$number =$_POST["t1"];
$fact = Factorial($number);
echo "Factorial $number = $fact";
?>
</form>
3
</body>
</html>
4
OUTPUT:
RESULT:
Thus the above program was successfully executed and verified.
5
EX.NO:3 PALINDROME OR NOT USING
FORMS DATE :
AIM :
To write a PHP program find palindrome or not using while loop
PROGRAM:
<html>
<head>
<title>PHP Program To Check a given number is Palindrome or Not</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num" value="" placeholder="Enter a number"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$n = $_POST['num'];
$x = $n;
$r = 0;
$n1= 0;
while($n>1)
{
$r = $n % 10;
$n1 = $n1 * 10 + $r;
$n = $n/10;
}
6
OUTPUT:
RESULT:
Thus the above program was successfully executed and verified.
7
EX.NO:4 BIGGEST NUMBER USING FUNCTION
DATE :
AIM :
To write a PHP program to Find Biggest Number using function
PROGRAM:
<html>
<head>
<title> biggest of three </title>
</head>
<body>
<center>
<form method="post">
enter first number: <input type="text" name="number1"><br><br>
enter second number: <input type="text" name="number2"><br><br>
enter third number: <input type="text" name="number3"><br><br>
<input type="submit" name="submit"><br><br>
</form>
</center>
<?php
if(isset($_POST['submit']))
{
$a=$_POST['number1'];
$b=$_POST['number2'];
$c=$_POST['number3'];
largest($a,$b,$c);
}
function largest($a,$b,$c)
{
if(($a>$b)and($a>$c))
echo"a is big:".$a;
elseif($b>$c)
echo"b is big:".$b;
8
else
echo"c is big:".$c;
?>
</body>
</html>
9
OUTPUT:
RESULT:
Thus the above program was successfully executed and verified.
10
EX.NO:5 DISPLAY BOOK DETAILS USING FOREACH
LOOP DATE :
AIM :
To write a PHP program to Perform display book details using ForEach Loop
PROGRAM:
<?php
$book=array("book name=php
Programming","price=300.00","aurthor=E.balagurusamy",
"edition=4th"); echo'<center>';
echo'<b>';
echo'<table>';
foreach($book as $value)
{
echo "$value<br>";
}
?>
10
OUTPUT:
RESULT:
Thus the above program was successfully executed and verified.
11
EX.NO:6 REVERSE THE
DIGIT DATE :
AIM :
To write a PHP program to find the reverse the digit of a given number
PROGRAM:
<html>
<head>
<title>PHP Program To find the Reverse of a given number</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num" value="" placeholder="Enter a number"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php if(isset($_POST['submit']))
$n = $_POST['num'];
$x = $n;
$r = 0;
12
while($n>1)
$r = $r*10;
$r = $r+($n%10);
$n = $n/10;
echo "Reverse of number ". $x . " is: " .$r;
return 0;
?>
</body>
</html>
13
OUTPUT:
RESULT:
Thus the above program was successfully executed and verified.
14
EX.NO:7 STUDENT MARK LIST
DATE :
AIM :
To write a PHP program to display student mark details using table.
PROGRAM:
<html>
<head>
<title>student marklist</title>
</head>
<body>
<center>
<table border=6 bgcolor="red">
<tr bgcolor="pink">
<th>name</th>
<th>register no</th>
<th>mark1</th>
<th>mark2</th>
<th>mark3</th>
<th>mark4</th>
<th>mark5</th>
</tr>
<tr>
<td>suthir
<td>11
<td>80
<td>18
15
<td>16
<td>118
<td>118
</tr>
<tr>
<td>sonu
<td>100
<td>80
<td>36
<td>10
<td>19
<td>18
</tr>
<tr>
<td>suku
<td>18
<td>80
<td>77
<td>33
<td>11
<td>12
</tr>
<tr>
<td>suresh
<td>100
<td>80
<td>23
16
<td>22
<td>22
<td>12
</tr>
<tr>
<td>sukuna
<td>100
<td>80
<td>18
<td>100
<td>11
<td>13
</tr>
</center>
</table>
</body>
</html>
17
OUTPUT:
RESULT:
Thus the above program was successfully executed and verified
18
EX.NO:8 GET INPUT FROM CLIENT PAGE AND PERFORM
ARITHMETIC OPERATION
DATE :
AIM :
To write a PHP program to get input from client page and perform arithmetic operations
PROGRAM:
<html>
<body>
<form method="post"> enter the first number:
<input type="text" name="number1"><br><br> enter the second number:
<input type="text" name="number2"><br><br>
<input type="submit" name="submit"><br><br>
</form>
<?php if(isset($_POST['submit']))
$number1=$_POST['number1'];
$number2=$_POST['number2'];
$sum=$number1+$number2;
$sub=$number1-$number2;
$pro=$number1*$number2;
$result=$number1/$number2; echo"sum=".$sum; echo'<br>'; echo"subraction=".$sub;
echo'<br>'; echo"multiplication=".$pro; echo'<br>'; echo"divison=".$result; echo'<br>';
?>
19
</body>
</html>
20
OUTPUT:
RESULT:
Thus the above program was successfully executed and verified
21
EX.NO.9 DISPLAY HE/SHE ELIGIBLE FOR VOTE OR NOT IN
SERVER PAGE
DATE:
AIM:
To write a PHP program to display he/she eligible for vote or not in server page
PROGRAM:
<html>
<body>
<form method="post"> enter your age :
<input type="text" name="number1">
<br>
<br>
<input type="submit" name="submit">
</form>
<?php
if(isset($_POST['submit']))
{
$age=$_POST['number1'];
if($age>=18)
echo"eligible to vote";
else
echo"ineligible to vote";
}
?>
</body>
</html>
22
OUTPUT:
RESULT:
Thus the above program was successfully executed and verified.
23
EX.NO:10 PERFORM STRING MANIPULATION AND DISPLAY IN
SERVER PAGE
DATE:
AIM:
To write a php program to perform string manipulation and display in server page.
PROGRAM:
<html>
<head>
<title>string functions</title>
</head>
<body>
<form method="post">
<center>
enter a string: <input type="text" name="str">
<input type="submit" name="submit">
</center>
</form>
<?php
if(isset($_POST['submit']))
{
$stre=$_POST['str'];
$strrev=strrev($stre);
$len=strlen($stre);
$ucase=strtoupper($stre);
$lcase=strtolower($ucase);
$strim=trim($stre);
echo"string reverse=".$strrev;
echo'<br>';
echo"string length=".$len;
echo'<br>';
echo"string upper=".$ucase;
echo'<br>';
echo"string lower=".$lcase;
echo'<br>';
echo"string trim=".$strim;
echo'<br>';
}
?>
</body>
</html>
24
OUTPUT:
RESULT:
Thus the above program was successfully executed and verified.
25