Last active
November 30, 2017 20:40
-
-
Save savasdersimcelik/402747b7c804cd568ad9b6250207b4f6 to your computer and use it in GitHub Desktop.
PHP Armstrong Sayılar Algoritması
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Author : Savaş Dersim ÇELİK | |
* Version: 1.0.0 | |
* Web: http://webinyo.com | |
* Mail: savasdersimcelik@gmail.com | |
* Description : Armstrong sayılar PHP Algoritması | |
*/ | |
function armstrong($param){ | |
$toplam = 0; | |
$parcala = str_split($param); | |
foreach ($parcala as $key => $value) { | |
$toplam = $toplam + pow($value, strlen($param)); | |
} | |
return $toplam; | |
} | |
$sayac = 0; | |
for ($i=1; $i < 100000; $i++) { | |
if (armstrong($i) == $i) { | |
echo $i. '<br>'; | |
$sayac++; | |
} | |
} | |
echo $sayac; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment