For Advertisements on this blog Contact Us at developgram@gmail.com or +91-9923438816

Simple Programming Tutorials For Beginners

Tuesday, April 18, 2017

Armstrong Number (1 - 500)

<html>
<head>
  <script>
    function armstrong(num)
    {
      var temp = parseInt(num);
      var sum = 0;
      var remainder;

      while (temp > 0)
      {
        remainder = parseInt(temp % 10);
        sum = parseInt(sum + remainder * remainder * remainder);
        temp = parseInt(temp / 10);
      }

      if (num == sum)
        document.write(num + "<br />");
    }
  </script>
</head>
<body>
  <script>
    for (i = 1; i < 500; i++)
    {
      armstrong(i);
    }
  </script>
</body>
</html>


No comments:

Post a Comment

SEARCH THIS BLOG