Re: Programming "Digits exploration"


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

Re: Programming "Digits exploration"



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
>
> Say the number was 16, then enter 1 for a, and 6 for B, then do what
> you want with the numbers.  Hope this helps! :)  Tell me if it works.
>


Or, you could do something like: (this is for the 82 and entirely off the
top of my head -- if it doesn't work, fix it.)
Input "NUMBER? ",N           ; get a number
0\->\T                       ; zero out total
While N>0
N/10\->\N
(10fPart N)\^2\+T\->\T       ; square the last digit and add it to T
iPart N\->\N
End
Then do T\->N\ and repeat the last 5 lines of code, and display or return T




Michael Castleman, mlc@sri.webmate.com       | "Only two things are infinite:
http://sri.webmate.com/members/mlc/home.html | the universe and human stupidity
                                             | -- and I'm not sure about the
**NOTE ADDRESS CHANGE!**                     | former." -Albert Einstein


References: