Qbasicnews.com

Full Version: Program to calculate the logarithm (log 10) of a number > 1
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
'program to calculate the logarithm (log 10) of a number > 1
'programa para calcular el logaritmo (log 10) de un numero > 1
'lrcvs 26.09.08

cls
input "Num. > 1 : "; n$
cls
i = len(n$)-1
for b# = i to (i + 1) step 1 / (10 ^ 5)
l# = 10 ^ b#
if l# >= val(n$) then print "el logaritmo de "; n$; " es = "; b#: end
next b#
Again, way too slow, just use the mathematical functions that are already available to you.

You have a number n#, must be > 0
The answer is then b# = LOG(n#) / LOG(10)

Done. No need for loops with stepsize 0.00001.
Hi, Neo:

Thanks for your advice.

Yes, I know the Log function of QBasic.

But, I wanted to do it my way.

I'm the old school..., ...I'm a turtle friend..., ...but Thanks, ...I learning now slowly !!!

The important for my, is that it works well.

Greeting from Spain


CLS
'Version 2.0 Ok!!!

'Este programa calcula el logaritmo (log10)
'de un numero entre 1 ... 999999999
'lrcvs 26.09.08
INPUT "Logaritmo de un numero > 1 : "; n$
INPUT "Precision ( 1...5) : "; p
PRINT "Solutions ( comparatives ):"
PRINT
x5# = LOG(VAL(n$)) / LOG(10#)
LOCATE 5, 1: PRINT "Solution of computer  = "; x5#
i = LEN(n$) - 1
j = i + 1
FOR b# = i TO j STEP 1 / (10 ^ p)
l# = 10 ^ b#
IF l# = VAL(n$) THEN CLS : PRINT "El (log 10 = ) de "; n$; " es = "; b#: GOTO 10
IF l# > VAL(n$) THEN LOCATE 6, 1: PRINT "Value by MAX of "; n$; " is = "; b#: x1# = b#: GOTO 10
NEXT b#
10 :
PRINT
l# = 0
FOR w# = i TO j STEP 1 / (10 ^ p)
l# = 10 ^ w#
IF l# < VAL(n$) THEN LOCATE 7, 1: PRINT "Value by MIN of "; n$; " is = "; w#: x2# = w#
NEXT w#
x3# = (x1# + x2#) / 2
LOCATE 8, 1: PRINT "Value average          = "; x3#