Author Topic: How does one multiply digits of a number?  (Read 5861 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: How does one multiply digits of a number?
« Reply #15 on: January 05, 2021, 06:22:54 pm »
LOL woops thanks Steve! What happened was that I had a strict 3 digit number and today I tossed in the random code without thinking it could be under 100. LOL

Honestly, your answer might be right and mine wrong.  It depends on how the teacher defines the problem.  After all, 14 *is* the same as 014.  Do we count leading zeroes?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: How does one multiply digits of a number?
« Reply #16 on: January 05, 2021, 06:25:35 pm »
premature optimization is the root of all evil
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How does one multiply digits of a number?
« Reply #17 on: January 05, 2021, 06:27:12 pm »
Well I hope no one feeds Steve's NumberOfDigits Function a negative number.

Signed,  Also Failed. ;-))

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: How does one multiply digits of a number?
« Reply #18 on: January 05, 2021, 06:32:08 pm »
Well I hope no one feeds Steve's NumberOfDigits Function a negative number.

Signed,  Also Failed. ;-))

Why would it fail for negative numbers?  Did you miss the compound line?

tempnum = ABS(num)

ABS(-123) = 123...  which would be 3 digits, or are you counting the sign as a digit?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How does one multiply digits of a number?
« Reply #19 on: January 05, 2021, 06:33:51 pm »
Yes I did miss, I fail again! ;-))

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: How does one multiply digits of a number?
« Reply #20 on: January 05, 2021, 06:35:56 pm »
Yes I did miss, I fail again! ;-))

Teach, can I get my grade changed??  LOL!
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How does one multiply digits of a number?
« Reply #21 on: January 05, 2021, 06:45:09 pm »
Maybe teach will show mercy if I do it how I would normally, no need for function creation:
Code: QB64: [Select]
  1.     n = INT(RND * 1000) ' just testing number 0 to 999
  2.     sn$ = STR$(n)
  3.     m = 1
  4.     FOR i = 2 TO LEN(sn$)
  5.         m = m * VAL(MID$(sn$, i, 1))
  6.     NEXT
  7.     PRINT n, m
  8.     SLEEP
  9.