javascript - breaking an integer into parts -


I am trying to add all the digits in an integer value unless I use javascript to be below 9 Get it

For an example, if I have 98, then I want to add them like 1 + 9 + 8 = 18, and 18 plus 9 plus 9 plus 1 + 8 is equal to 9 . Instead of giving you a full code, let me tell you how to do it.

Until you get 0 to get all the digits of a number, you can do the number% 10 and then the int divide according to 10 (number / 10). Calculate individual digits and get up to par & gt; 9 Repeat the above process in a loop.

Edit : Ok here is the code for you:

   gt; 0) {rem = (n% 10); Sum + = rem; N = (n - rim) / 10; } N = sum; } While (Yoga> 9); Warning ("sum:" + sum); & Lt; / Script & gt;    

Comments