'Program arithmetic division with integers numbers

Announce and discuss the progress of your various programming-related projects...programs, games, websites, tutorials, libraries...anything!

Moderators: Pete, Mods

Post Reply
lrcvs
Veteran
Posts: 58
Joined: Mon Mar 10, 2008 9:28 am

'Program arithmetic division with integers numbers

Post by lrcvs » Sat Jan 09, 2010 4:23 am

'Program arithmetic division with integers numbers
'lrcvs
'09 Jan 2010


cls
a$ = "9876598743014313"
b$ = "388798006"

'A:B

la = len (a$)
c$ = string$(la,"0")
for r = 1 to la
for s = 0 to 9
mid$(c$,r) = ltrim$(str$(s))
gosub check
if val(v$) = val(a$) then print v$:goto 10
if val(a$) > val(v$) then mid$(c$,r) = ltrim$(str$(s))
if val(a$) < val(v$) then mid$(c$,r) = ltrim$(str$(s-1)): goto 10
next s
10:
next r

R$ = ltrim$(str$(val(a$)-(val(c$)*val(b$))))
d$ = ltrim$(str$(val(r$)/val(b$)))

print "Program = ";ltrim$(str$(val(c$)))+right$(d$,len(d$)-1)
print
print "Remanence = ";r$
print
print "Computer = ";val (a$) / val (b$)

sleep
end

check:
v$ = ltrim(str$(val (c$) * val (b$)))
return

lrcvs
Veteran
Posts: 58
Joined: Mon Mar 10, 2008 9:28 am

Now is more easy !!!

Post by lrcvs » Sat Jan 09, 2010 2:24 pm

'Program arithmetic division with integers numbers
'lrcvs
'09 Jan 2010

Dim a, b, c, v, t, d as string
Dim la, r,s as integer

Cls
a = "12345678956353565"
b = "3698"

la = Len (a)
c = String$(la,"0")
For r = 1 To la
For s = 0 To 9
Mid$(c,r) = Ltrim$(Str$(s))
v = Ltrim(Str$(Val (c) * Val (b)))
If Val(v) = Val(a) Then Print v: Exit For
If Val(a) > Val(v) Then Mid$(c,r) = Ltrim$(Str$(s))
If Val(a) < Val(v) Then Mid$(c,r) = Ltrim$(Str$(s-1)): Exit For
Next s
Next r

t = Ltrim$(Str$(Val(a)-(Val(c)*Val(b))))
d = Ltrim$(Str$(Val(t)/Val(b)))

Print "Program = ";ltrim$(Str$(Val(c)))+Right$(d,Len(d)-1)
Print
print "Remanence = ";t
Print
print "Computer = ";val (a) / Val (b)
End

Post Reply