Friday, August 10, 2012

konversi desimal ke octal

Ini tugas kedua yaitu konversi dari desimal ke octal

berikut codingnya:

<?php
if (isset ($_POST['decimal'])) {
    $decimal = $_POST['decimal'];
    $original = $_POST['decimal'];
    if (preg_match('/[^0-9]/', $decimal)){
        die("Maaf, inputan salah ...");
    }
    else {

          $oct = decoct($decimal);
         
   

      $result = strrev($oct);
      echo "<h2>Bilangan $original (desimal) dalam bentuk octal adalah $result,<a href = 'konversi_desimal_ke_octal.php'>Back</a> to the script";
        }
}
else {
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>php converter</title>
    </head>
    <body>
       <form action="<?
        echo $_SERVER ['PHP_SELF'];
                    ?>"
             method="post">
           <h1>Masukkan Bilangan Desimal Disini (Cepat !!!) </h1>
           <input type="text" size="50" name="decimal"> <br>
           <input type="submit" value="konversi">
   
       </form>
   
    </body>
</html>
<?php
}
?>
berikut adalah contohnya pada web:
setelah di run (shift+f6)


setelah dimasukkan nilai
dan ini hasilnya :D

No comments: