Tech Study

Write a PHP program to check if a number is an Armstrong number or not

Introduction

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following excercise..

 <?php
function armstrong_number($num) {
  $sl = strlen($num);
  $sum = 0;
  $num = (string)$num;
  for ($i = 0; $i < $sl; $i++) {
    $sum = $sum + pow((string)$num{$i},$sl);
  }
  if ((string)$sum == (string)$num) {
    return "True";
  } else {
    return "False";
  }
}
echo "Is 371 Armstrong number? ".armstrong_number(371);
echo "<br>Is 21 Armstrong number? ".armstrong_number(8208);
echo "<br>Is 4587 Armstrong number? ".armstrong_number(10);"\n";

Result

Write a PHP program to check if a number is an Armstrong number or not
Write a PHP program to check if a number is an Armstrong number or not

TaggedWrite a PHP program to check if a number is an Armstrong number or not

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more