Program to calculate the logarithm (log 10) of a number > 1 - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Projects (http://qbasicnews.com/newforum/forum-12.html) +--- Thread: Program to calculate the logarithm (log 10) of a number > 1 (/thread-10167.html) |
Program to calculate the logarithm (log 10) of a number > 1 - lrcvs - 09-27-2008 '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# Re: Program to calculate the logarithm (log 10) of a number > 1 - Neo - 09-28-2008 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. Re: Program to calculate the logarithm (log 10) of a number > 1 - lrcvs - 09-28-2008 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 Re: Program to calculate the logarithm (log 10) of a number > 1 Ver:2.001 Ax - lrcvs - 09-28-2008 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 ):" 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 : 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# |