Assignment3 Seta
Assignment3 Seta
Q1.) Write a script to accept two integers(Use html form having 2 textboxes).
Write a PHP script to,
a. Find mod of the two numbers.
b. Find the power of first number raised to the second.
c. Find the sum of first n numbers (considering first number as n)
d. Find the factorial of second number.
//html
<html>
<body>
//seta1.php
<?php
function mod($x,$y)
$z=$x%$y;
$f= 1;
$n1 = $y;
while($n1 > 0)
$f= $f * $x;
$n1--;
}
echo "$x raised to the power $y = $f <br>";
function sum($x)
$sum=0;
$i=1;
while($i<=$x)
$sum=$sum+$i;
$i++;
function fact($y)
$i=1;$f=1;
while($i<=$y)
$f=$f*$i;
$i++;
$x=$_POST['t1'];
$y=$_POST['t2'];
mod($x,$y);
power($x,$y);
sum($x);
fact($y);
?>
Q2.) Write a PHP script to accept 2 strings from the user, the first string should be a sentence and
second can be a word.
a. Delete a small part from first string after accepting position and number of characters to
remove.
b. Insert the given small string in the given big string at specified position without removing any
characters from the big string.
c. Replace some characters/ words from given big string with the given small string at specified
position.
d. Replace all the characters from the big string with the small string after a specified position.
<html>
<body>
</form>
</body>
</html>
//seta2_1.php
<?php
include("seta2_2.php");
$x=$_POST['txt1'];
$y=$_POST['op'];
if($y=="len")
getlength($x);
}
else if($y=="Vowels")
vowel($x);
else
if($y=="convert")
change($x);
else
if($y=="pad")
padding($x);
else
if($y=="sp")
remove($x);
else
if($y=="rev")
reverse($x);
}
else
echo"invalid choice";
?>
//seta2_2.php
<?php
function getlength($s)
function vowel($s)
$cnt=0;
for($i=0;$i<strlen($s);$i++)
if($s{$i}=='a'||$s{$i}=='e'||$s{$i}=='i'||$s{$i}=='o'||$s{$i}=='u')
$cnt++;
function change($s)
function padding($s)
$p=str_pad($s,15,"*",STR_PAD_BOTH);
function remove($s)
{
echo "after removing white spaces from begining".ltrim($s);
function reverse($s)
?>