PHP Girilen Sayının Faktöriyelini Bulma - Bilişim Konuları

PHP Girilen Sayının Faktöriyelini Bulma

Bu örneğimizde php ile kullanıcının klavyeden girmiş olduğu bir sayının faktöriyelini bularak sonucu ekranda gösteren php kodunu yapacağız. Öncelikle kullanıcının istediği sayıyı girebilmesi için bir form sayfası oluşturacağız. Daha sonra ise formda girilen sayıyı ikinci php sayfasına göndererek bu sayfada girilen sayının faktöriyelini hesaplatacağız ve sonucu ekranda göstereceğiz. Programın ekran görüntüleri, php sayfalarının kodları ve çalışan hali aşağıda gösterilmiştir.

Ekran görüntüleri:

Aşağıdaki resimde form dosyasına 4 sayısı girilmekte ve hesaplama sayfasına gönderilmektedir.

php-faktoriyelhesaplama1

Aşağıdaki resimde formdan gelen sayının faktöriyeli hesaplanmakta ve sonucu yazdırılmaktadır.

php-faktoriyelhesaplama2

Aşağıdaki resimde form dosyasına 6 sayısı girilmekte ve hesaplama sayfasına gönderilmektedir.

php-faktoriyelhesaplama3

Aşağıdaki resimde formdan gelen sayının faktöriyeli hesaplanmakta ve sonucu yazdırılmaktadır.

php-faktoriyelhesaplama4

phpfaktoriyelhesaplama1.php kodları:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Faktöriyel Hesaplama-1</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>

<form action="phpfaktoriyelhesaplama2.php" method="post">
<table border="0" bgcolor="#FF66FF">
  <tr>
    <td colspan="2" align="center">Faktöriyeli Hesaplanacak Sayıyı Giriniz</td>
    </tr>
  <tr>
    <td>Sayı:</td>
    <td><input name="fak" type="text" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input name="gonder" type="submit" value="Faktöriyeli Hesapla" /></td>
  </tr>
</table>

</form>
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- BannerKucuk -->
<ins class="adsbygoogle"
     style="display:inline-block;width:468px;height:60px"
     data-ad-client="ca-pub-2151654795043080"
     data-ad-slot="8393636475"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</body>
</html>

phpfaktoriyelhesaplama2.php dosyasının kodları:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Faktöriyel Hesaplama-2</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>

  <?php
$fak=$_POST['fak'];

 $faktor=1;
    for ($i=1; $i<=$fak;$i++)
	{
    	$faktor=$faktor*$i;
	}

?>

<table border="0" bgcolor="#99FF99">
  <tr>
    <td colspan="2" align="center">Girilen Sayının Faktöriyeli</td>
  </tr>
  <tr>
    <td>Girilen Sayı:</td>
    <td><strong><?php echo $fak; ?></strong></td>
  </tr>
  <tr>
    <td>Faktöriyeli:</td>
    <td><strong><?php echo $faktor; ?></strong></td>
  </tr>
</table>
<p><A HREF="javascript:javascript:history.go(-1)">Geri dön</A></p>

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- BannerKucuk -->
<ins class="adsbygoogle"
     style="display:inline-block;width:468px;height:60px"
     data-ad-client="ca-pub-2151654795043080"
     data-ad-slot="8393636475"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</body>
</html>

Kendin DENE

Bu Yazıya Tepkin Nedir?
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

<< Önceki Yazı

Yorum Yap