kali ini saya akan post cara buat file php tentang while dan faktorial...
sebelumnya anda harus install xampp terlebih dahulu di laptop anda karna file nya akan di save di xampp folder htdocs dan anda harus buat folder baru lagi terserah anda namanya apa agar bisa jalan program php nya ...
cara menjalankannya anda buka browser yang biasa anda gunakan kemudian di pencarian anda ketik ( localhost/nama folder yang di dalam di htdocs/kemudian nama file phpnya)
untuk background terserah anda gambarnya harus di save di folder yang sama dengan file php nya.
1. coding untuk for while/while :
<body background="321010043.jpg">
<?php
for ($i= 1; $i <= 1; $i++)
{
echo "1";
echo "<br />";
echo "<br />";
}
for ($i= 2; $i <= 3; $i++)
{
echo "2 ";
}
echo "<br/>";
echo "<br/>";
for ($i= 3; $i <= 5; $i++)
{
echo "3 ";
}
echo "<br/>";
echo "<br/>";
for ($i= 4; $i <= 7; $i++)
{
echo "4 ";
}
echo "<br/>";
echo "<br/>";
for ($i= 5; $i <= 9; $i++)
{
echo "5 ";
}
echo "<br/>";
echo "<br/>";
?>
<<<=============================================>>>
coding faktorial :
<html>
<head>
<title> ==>> Menghitung Bilangan Faktorial <<== </title>
<style>
</style>
</head>
<body>
<body background="321010043.jpg">
<?php
$n = isset($_POST['n']) ? $_POST['n'] : NULL;
if(isset($_POST['submit'])){
if($n!=NULL){
$bil = 1;
for($i=1;$i<=$n;$i++){
$bil = $bil*$i;
}
}else{
$bil = 'Bilangan Tidak boleh kosong !';
}
}
echo '<div class="panel">';
echo '<h2>Menghitung Bilangan Faktorial</h2>';
echo '<h4>Masukkan Bilangan :</h4>';
echo '<form action="" method="post">';
echo '<input class="field" type="text" name="n" value="'.$n.'" placeholder="Masukkan Bilangan..."/>';
echo '<input class="tombol" type="submit" name="submit" value="Hitung"/>';
echo '</form>';
if((isset($n))and($n!=NULL)){
echo '<h4>Hasil Faktorial :</h4>';
echo '<=> ';
for($i=1;$i<$n;$i++){echo $i.'x';}
echo $n;
echo '<br/>';
}
echo '<h4>Jumlah Faktorial :</h4>';
echo '<input class="field" type="text" value="'.(isset($bil) ? $bil : NULL).'" readonly/>';
echo '</div>';
?>
</body>
</html>
hasil screenshoot :
<<<======================================>>>
bila kurang jelas atau ada yang masih error komen aja gan ...
- Blogger Comment
- Facebook Comment
Langganan:
Posting Komentar
(
Atom
)
0 komentar:
Posting Komentar