Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algorithm to determine if a number A is a power of B.
#2
I do programs like these at compitions. Took me not even 5 mins.

Code:
CLEAR
CLS
INPUT "Number: ", A
INPUT "Base: ", B
Value = 0
IsIt = 0
index = -1
DO
IF Value > A THEN EXIT DO
index = index + 1
Value = B ^ index
IF Value = A THEN IsIt = 1: EXIT DO
LOOP
Message$ = "No, it is not a power of" + STR$(B)
IF IsIt = 1 THEN Message$ = "Yes, it is a power of" + STR$(B)
PRINT Message$
END

There you go! Big Grin Challenge Complete!

BTW, Test your program: A = 1, B = anynumber. 1 is a power of ANY number! anynumber ^ 0 = 1.
i]"But...it was so beautifully done"[/i]
Reply


Messages In This Thread
Algorithm to determine if a number A is a power of B. - by Mitth'raw'nuruodo - 02-28-2005, 09:06 AM
Here's my effort - by Quibbler - 05-31-2005, 07:16 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)