-
Notifications
You must be signed in to change notification settings - Fork 3
/
printStars.php
65 lines (53 loc) · 1.28 KB
/
printStars.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require_once "templates/header.php";
function solution(){
if(isset($_POST['submit'])){
$n = $_POST['num'];
$message = "Rows can\'t be negative!!";
if($n < 0){
echo "<script type='text/javascript'>
alert('". $message ."');
</script>";
exit();
}else {
echo "<font size='3em' style='float: left;'>".
"(Here rows = ".$n.
")</font><br /><br />";
}
for ($i = 1; $i <= $n; $i++){
for ($j=0; $j < $i; $j++){
print("*");
}
echo "<br>";
}
}
}
?>
<header class="text-center">
<h1>Print stars like:</h1>
<p class="para">
* <br />
** <br />
*** <br />
**** <br />
</p>
</header>
<div id="container">
<div id="menu">
</div>
<form action="" method="POST" class="form">
<div class="form-group">
<h3>Enter the number of rows: </h3> <br />
<center>
<input type="number" name="num" class="inputBox" placeholder="Rows" /> <br />
<button type="submit" name="submit">Check</button> <br />
</center>
<p id="para">
<br /> <?= solution(); ?> <br />
</p>
</div>
</form>
</div>
<?php
require_once "templates/footer.php";
?>