Kullanıcının girdiği iki sayı ve bir operatör değerine göre, dört işlemi gerçekleştiren PHP kodunu yazınız.
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 66 67 68 | <!doctype html> <html> <head> <meta charset="utf-8"> <title>www.yazilimbilisim.net - PHP Örnekleri</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"> </head> <body> <div class="container"> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <div class="form-group"> <label for="sayi1">Sayı 1</label> <input type="text" class="form-control" name="sayi1"> </div> <div class="form-group"> <label for="sayi2">Sayı 2</label> <input type="text" class="form-control" name="sayi2"> </div> <div class="form-group"> <label for="secim">İşlem Seçin</label> <select name="secim" class="form-control"> <option value="+">TOPLA</option> <option value="-">FARK</option> <option value="*">ÇARPIM</option> <option value="/">BÖLÜM</option> </select> </div> <button type="submit" name="kontrol" class="btn btn-default" >ÇALIŞTIR</button> </form> </div> <!-- PHP KODLARI --> <div class="container"> <table class="table table-striped"> <?php if(isset($_POST["kontrol"]))//kontrol adında bir form nesnesi var mı kontrolü yapılıyor { $sayi1=$_POST["sayi1"]; $sayi2=$_POST["sayi2"]; $secim=$_POST["secim"]; $sonuc=0; if($secim == '+') { $sonuc=$sayi1+$sayi2; } elseif($secim == '-') { $sonuc=$sayi1-$sayi2; } elseif($secim == '*') { $sonuc=$sayi1*$sayi2; } elseif($secim == '/') { $sonuc=$sayi1/$sayi2; } echo "<h1 class='text-info'>$sonuc</h1>"; } ?> </table> </div> </body> </html> |
Add Comment