index.html
<html>
<head>
<title>no 1</title>
</head>
<body>
<br>
<form action="nilai.php" method="post" target="_blank">
<table align="center" >
<tr>
<td colspan="3" align="center">Menentukan Nilai Yang Terbesar</td>
</tr>
<tr>
<td colspan="3">=================================</td>
</tr>
<tr>
<td>Nilai X</td>
<td>:</td>
<td><input type="text" size="30" name="x"></td>
</tr>
<tr>
<td>Nilai Y</td>
<td>:</td>
<td><input type="text" size="30" name="y"></td>
</tr>
<tr>
<td><input type="submit" value="Ok?"></td>
</tr>
</table>
</body>
</html>
nilai.php
<?php$x=$_POST["x"];
$y=$_POST["y"];
echo "Nilai 1: " .$x. " dan Nilai 2: " .$y. "<br><br>";
if($x>$y){
echo " " .$x. " lebih besar dari " .$y. " ";
}else if($y>$x){
echo " ".$y." lebih besar dari ".$x." ";
}else echo"Nilai x & y sama";
?>
2. buatlah perulangan dengan for, while dan do while
<?php
$i = 1;
while ($i <= 10) {
echo $i++;
}
echo "<br>";
echo "<br>";
$i
= 0;
do {
echo $i;
} while ($i > 0);
echo "<br>";
echo "<br>";
for($i=0;$i<5;$i++){
echo "Hello World!";
echo "<br>";
echo "Learn PHP";
echo "<br>";
}
?>
3 buatlah aplikasi dengan fungsi fungsi PHP minimal 5 fungsi
<?php
function writeName($fname)
{
echo $fname . "<br />";
}
echo "Nama : ";
writeName("Endri Rahmawanto");
echo "NIM : ";
writeName("09018250");
echo "<br>";
?>
<br>
<li>fungsi 1 - Penjumlahan</li>
<?php
function add($x,$y)
{
$total=$x+$y;
return $total;
}
echo "1 + 2 = " . add(1,1);
echo "<br>";
?>
<br>
<li>fungsi 2 - Pengurangan</li>
<?php
function add2($x,$y)
{
$total=$x-$y;
return $total;
}
echo "2 - 1 = " . add2(2,1);
echo "<br>";
?>
<br>
<li>fungsi 3 - Pengkalian</li>
<?php
function add3($x,$y)
{
$total=$x*$y;
return $total;
}
echo "2 x 6 = " . add3(2,6);
echo "<br>";
?>
<br>
<li>fungsi 4 - Pembagian</li>
<?php
function add4($x,$y)
{
$total=$x/$y;
return $total;
}
echo "20 : 5 = " . add4(20,5);
echo "<br>";
?>
<br>
<li>fungsi 5 - Pangkat</li>
<?php
function add5($x)
{
$total=$x*$x;
return $total;
}
echo "Pangkat 3 = " . add5(3);
?>
Tidak ada komentar:
Posting Komentar