rakesh830566

Armstrong Series

May 28th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.15 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <title>Assignment 4.7</title>
  7. </head>
  8.  
  9. <body>
  10.     <h3>Write a program of Armstrong Series</h3>
  11.     <hr>
  12.     <script type="text/javascript">
  13.         // Take input a number from user
  14.         var userInput = Number(prompt('Enter a number to print Armstrong Series...'));
  15.  
  16.         // Displaying number which is entered by user
  17.         document.write('Entered number by you = <strong>' + userInput + '</strong><br><br>');
  18.  
  19.         // Displaying series of armstrong number
  20.         for (var i = 0; i <= userInput; i++) {
  21.            var temp = 0; //it will store calculation of evetry number to check its armstrong or not
  22.            var splittedArray = String(i).split(''); // it will store array for of every number
  23.            for (x in splittedArray) {
  24.                temp += ((Number(splittedArray[x])) ** splittedArray.length); // here done the calculation for armstrong number
  25.            }
  26.            if (i === temp) {
  27.                document.write(i + "<br>"); // here displaying the armstrong number if it is
  28.             }
  29.         }
  30.     </script>
  31. </body>
  32.  
  33. </html>
Add Comment
Please, Sign In to add comment