Qbasicnews.com
December 15, 2018, 12:02:55 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Program to calculate the logarithm (log 10) of a number > 1  (Read 7100 times)
lrcvs
Member
*
Posts: 56


« on: September 27, 2008, 07:54:21 AM »

'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#
« Last Edit: September 27, 2008, 06:06:30 PM by lrcvs » Logged
Neo
Na_th_an
*****
Posts: 2150



« Reply #1 on: September 27, 2008, 06:43:34 PM »

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.
Logged
lrcvs
Member
*
Posts: 56


« Reply #2 on: September 27, 2008, 07:09:01 PM »

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


Logged
lrcvs
Member
*
Posts: 56


« Reply #3 on: September 28, 2008, 02:38:04 PM »

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#
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!