Since everyone has made them already, here is mine.
Heck, I'll up the ante once more, and do the whole homework problem as it was presented: "we have a task to make a program that adds up digits of any number above 1000, But there's a second part, to multiply a number below 1000 - how does one make a program for that?"
INPUT "Enter a number =>"; num
n = NumberOfDigits(num)
result = result + GetDigit(num, i)
PRINT "The sum of the digits is:";
result = 1
result = result * GetDigit(num, i)
PRINT "The product of the digits is:";
PRINT "Do another? (Y/N)" result = 0
NumberOfDigits = NumberOfDigits + 1
tempnum = tempnum \ 10
GetDigit
= (Num
MOD 10 ^ Digit
) \
10 ^ (Digit
- 1)
I think this little example showcases the difference in style for how I tend to program and how most folks here on the forums do. When I see this type problem, my brain breaks it down into simple steps:
Step 1: Determine how many digits a number has.
Step 2: How to get any singular digit from that number.
Step 3: Manipulate those digits.
Once my brain has analyzed the problem, I then break it down into tools and sub-sections to solve each task. I'm notorious to never write "disposable code", which just does one thing and then I can toss it -- instead, I try and write code which can break down into Functions and Subs which I can forever import into use in future programs, without having to rewrite them repeatedly.
I didn't have a function to get NumberOfDigits in a number, but I do now. I didn't have a function to GetDigit from a number, but I do for it also, now.
My advice is:
Don't just code to solve today's problems. Code to create a toolset which can be used to help solve tomorrow's.