<html>
<head>
<meta charset="UTF-8">
<title>Pattern</title>
</head>
<body>
<form action="" method="post">
<h1><u>PHP project to print patterns</u></h1>
<h3>Please choose a pattern to print</h3>
1.<image src="1.jpg"/>
2.<image src="2.jpg"/>
3.<image src="3.jpg"/> <br/><br/>
Enter your choice : <input type="text" name="pat"/><br/><br/>
Enter no of rows : <input type="text" name="r"/><br/><br/>
<br/><input type="submit" name="btn" value="Print Pattern"/><br/><br/>
<?php
if(isset($_POST['btn']))
{
$n= $_POST['r'];
if($_POST['pat']==1)
{
for($x=0;$x<=$n;$x++)
{
for($y=1;$y<=$x;$y++)
{
echo "*";
}
echo "<br>";
}
}
elseif ($_POST['pat']==2)
{
for($x=$n;$x>=1;--$x)
{
for($y=1;$y<=$x;++$y)
{
echo "*";
}
echo "<br>";
}
}
elseif ($_POST['pat']==3) {
$temp=$n;
for($row=1;$row<=$n;$row++)
{
for($c=1;$c<$temp;$c++)
{
echo "  ";
}
$temp--;
for ($c = 1; $c <= 2 * $row - 1; $c++) {
echo "*";
}
echo "<br>";
}
}
else
echo "<br/>Invalid Input!!!";
}
?>
</form>
</body>
</html>
<head>
<meta charset="UTF-8">
<title>Pattern</title>
</head>
<body>
<form action="" method="post">
<h1><u>PHP project to print patterns</u></h1>
<h3>Please choose a pattern to print</h3>
1.<image src="1.jpg"/>
2.<image src="2.jpg"/>
3.<image src="3.jpg"/> <br/><br/>
Enter your choice : <input type="text" name="pat"/><br/><br/>
Enter no of rows : <input type="text" name="r"/><br/><br/>
<br/><input type="submit" name="btn" value="Print Pattern"/><br/><br/>
<?php
if(isset($_POST['btn']))
{
$n= $_POST['r'];
if($_POST['pat']==1)
{
for($x=0;$x<=$n;$x++)
{
for($y=1;$y<=$x;$y++)
{
echo "*";
}
echo "<br>";
}
}
elseif ($_POST['pat']==2)
{
for($x=$n;$x>=1;--$x)
{
for($y=1;$y<=$x;++$y)
{
echo "*";
}
echo "<br>";
}
}
elseif ($_POST['pat']==3) {
$temp=$n;
for($row=1;$row<=$n;$row++)
{
for($c=1;$c<$temp;$c++)
{
echo "  ";
}
$temp--;
for ($c = 1; $c <= 2 * $row - 1; $c++) {
echo "*";
}
echo "<br>";
}
}
else
echo "<br/>Invalid Input!!!";
}
?>
</form>
</body>
</html>
No comments:
Post a Comment