Re: Programming "Digits exploration"


[Prev][Next][Index][Thread]

Re: Programming "Digits exploration"



Come on, this is not that hard a problem.  I am intentionally not writing
this in TI basic because, while similar, each calculator has different
functions available.


Assume your number is in num, and the sum of squares is to be in sq.


sq = 0                                  ;initialize square total


while num <> 0
  x = num mod 10                        ;mod is modulo arithmetic
  sq = sq + x^2                         ;add in the squared digit
  num = (num - x) / 10                  ;strip out the low order digit
end


The modulo function is the integer remainder when doing an integer division.
For example 25 mod 10 is 5,  18 mod 4 is 2, etc.


I believe that mod is available on the 85, but not on the 82.


hope this helps


domroy






At 17:19 8/13/96 -0400, you wrote:
>On Tue, 13 Aug 1996, Mark Malley wrote:
>
>> AE>Hope you can help me. I wish to write a program that will take a two digit
>> AE>number and find the sum of the squares of its digits, take the new number
>> AE>and perform the same procedure. My problem is how to 'separate' the digits
>> AE>of the number as part of a program.
>> Why don't you do something like...
>> Prompt A
>> Prompt B
>
>If you want to input one number, here is the 'real' math way:
>
>say your nmber is 678
>
>to get the 2nd digit, use this:
>(Where x is your number)
>(y the digit you want...)
>
>(10*fpart (x/(10^(y-1))))-(fpart (x/(10^(y))))
>
>+------------------------------+-------------------------------+
>|        Tony Lieuallen        |   marvin@mars.superlink.net   |
>+------------------------------+-------------------------------+
>|             http://mars.superlink.net/marvin/home            |
>|       http://www.geocities.com/SiliconValley/Park/1171/      |
>+-------------------------Finger me for more of what follows!--+
>| * It's Non-Toxic! That means you can eat it!!                |
>| * The computer saves man a lot of guesswork, but then, so    |
>|   does the bikini.                                           |
>| * Practice makes perfect, but no one's perfect, so why       |
>|   practice?                                                  |
>| * The nice thing about Windows is - it does not just crash,  |
>|   it displays a dialog box, and let's you press 'OK' first.  |
>+--------------------------------------------------------------+
>


References: