User:Xkrouhn: Difference between revisions
Content added Content deleted
(Don't mark your user page as a task) |
|||
Line 19: | Line 19: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
<lang qbasic> |
<lang qbasic> |
||
' |
'program to transform a decimal number to fraction |
||
'LRCVS 11.06.11 |
|||
declare sub exacto (a$) |
declare sub exacto (a$) |
||
declare sub puro (a$, b$()) |
declare sub puro (a$, b$()) |
||
declare sub mixto (a$, b$()) |
declare sub mixto (a$, b$()) |
||
declare |
declare function factor (j , k ) as integer |
||
dim as integer l, r, s, t, k, w1, i, m, x, ll, pp, ps, u, v, j |
dim as integer l, r, s, t, k, w1, i, m, x, ll, pp, ps, u, v, j |
||
dim as string a, c, d |
dim as string a, c, d, a2 |
||
dim y () as string |
dim y () as string |
||
Line 36: | Line 34: | ||
cls |
cls |
||
input "Decimal number = ";a$ |
input "Decimal number = ";a$ |
||
⚫ | |||
print |
print |
||
if instr(a$,".") = 0 then print " |
if instr(a$,".") = 0 then print "It's not a decimal number " : goto 100 |
||
cls |
cls |
||
l = len(a$) |
l = len(a$) |
||
Line 87: | Line 86: | ||
next r |
next r |
||
print " |
print "decimal number = ";a$ |
||
print |
print |
||
'if b$(1) <> "" then print "repeticion = ";b$(1) |
|||
⚫ | |||
ll = len(a$) |
ll = len(a$) |
||
pp = instr(a$,".") |
pp = instr(a$,".") |
||
Line 96: | Line 94: | ||
ps = instr(d$,b$(1)) |
ps = instr(d$,b$(1)) |
||
if ps = 0 then |
if ps = 0 then |
||
print " |
print "Decimal number exact" |
||
print |
print |
||
call exacto (a$) |
call exacto (a$) |
||
end if |
end if |
||
if ps = 1 then |
if ps = 1 then |
||
print " |
print "Decimal number pure" |
||
print |
print |
||
call puro (a$, b$()) |
call puro (a$, b$()) |
||
Line 107: | Line 105: | ||
if ps > 1 then |
if ps > 1 then |
||
print " |
print "Decimal number mix" |
||
print |
print |
||
call mixto (a$, b$()) |
call mixto (a$, b$()) |
||
Line 117: | Line 115: | ||
end |
end |
||
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
|||
⚫ | |||
sub exacto (a as string) |
|||
dim as integer b, c, d, g, may, j, k, l, r, s, u, v, w, f |
dim as integer b, c, d, g, may, j, k, l, r, s, u, v, w, f |
||
dim as string z, h, g1 |
dim as string z, h, g1 |
||
Line 123: | Line 122: | ||
c = instr(a$,".") |
c = instr(a$,".") |
||
d = b - c |
d = b - c |
||
⚫ | |||
g = int(val(a$)) |
g = int(val(a$)) |
||
h$ = right$(a$, b - c) |
h$ = right$(a$, b - c) |
||
Line 130: | Line 128: | ||
j = 10^d |
j = 10^d |
||
k = val(h$) |
k = val(h$) |
||
for n = 9 to 1 |
for n = 9 to 1 step - 1 |
||
if j mod (1*(10^n)) = 0 and k mod (1*(10^n)) = 0 then j = j/(1*(10^n)) : k = k/(1*(10^n)) : |
if j mod (1*(10^n)) = 0 and k mod (1*(10^n)) = 0 then j = j/(1*(10^n)) : k = k/(1*(10^n)) :exit for |
||
next n |
|||
⚫ | |||
if j > k then may = j else may = k |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
next n |
next n |
||
l = factor (j,k) |
|||
u = k/l |
u = k/l |
||
v = j/l |
v = j/l |
||
w = (g * v) + u |
w = (g * v) + u |
||
⚫ | |||
print w;"/";v ;" = " ;w/v |
print w;"/";v ;" = " ;w/v |
||
end sub |
end sub |
||
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
|||
sub puro (a as string, b() as string) |
sub puro (a as string, b() as string) |
||
dim as integer b2, c, d, g, may, j, k, l, |
dim as integer b2, c, d, g, may, j, k, l, u, v, w, f, lr,x5 |
||
dim as string z, h, g1, x |
dim as string z, h, g1, x, a3 |
||
'decimal puro |
|||
z$ = b$(1) |
z$ = b$(1) |
||
⚫ | |||
lr = len (z$) |
lr = len (z$) |
||
b2 = len (a$) |
b2 = len (a$) |
||
Line 156: | Line 152: | ||
g = int (val(a$)) |
g = int (val(a$)) |
||
b2 = len(z$) + 1 + len(str$(g)) |
b2 = len(z$) + 1 + len(str$(g)) |
||
a3$ = str$(g) + "." + z$ |
|||
h$ = right$( |
h$ = right$(a3$, b2 - c) |
||
may = 0 |
may = 0 |
||
x$ = "" |
x$ = "" |
||
for n = 1 to lr |
for n = 1 to lr |
||
Line 167: | Line 163: | ||
j = val(x$) |
j = val(x$) |
||
k = val(h$) |
k = val(h$) |
||
⚫ | |||
for n = 9 to 1 |
for n = 9 to 1 step - 1 |
||
if j mod (1*(10^n)) = 0 and k mod (1*(10^n)) = 0 then j = j/(1*(10^n)) : k = k/(1*(10^n)) : |
if j mod (1*(10^n)) = 0 and k mod (1*(10^n)) = 0 then j = j/(1*(10^n)) : k = k/(1*(10^n)) :exit for |
||
next n |
|||
if j > k then may = j else may = k |
|||
⚫ | |||
r = (j mod n) |
|||
s = (k mod n) |
|||
if r = 0 and s = 0 then l = n |
|||
next n |
next n |
||
l = factor (j,k) |
|||
u = k/l |
u = k/l |
||
v = j/l |
v = j/l |
||
w = (g * v) + u |
w = (g * v) + u |
||
print w;"/";v ;" = ";w/v |
print w;"/";v ;" = ";w/v |
||
⚫ | |||
print "Option >>> " |
|||
⚫ | |||
end sub |
end sub |
||
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
|||
sub mixto (a as string, b() as string) |
sub mixto (a as string, b() as string) |
||
dim as integer b3, c, d, g |
dim as integer b3, c, d, g, j, k, l, u, v, w, f, lr, lz, ly, x5 |
||
dim as string z, h, g4, g7, x, y |
dim as string z, h, g4, g7, x, y |
||
Line 197: | Line 193: | ||
b3 = (val(y$)*(9*(10^ly))) + ((1*(10^ly))* (val(z$))) |
b3 = (val(y$)*(9*(10^ly))) + ((1*(10^ly))* (val(z$))) |
||
c = (9*(10^ly))*(1*(10^ly)) |
c = (9*(10^ly))*(1*(10^ly)) |
||
⚫ | |||
j = b3 |
j = b3 |
||
k = c |
k = c |
||
for n = 9 to 1 |
for n = 9 to 1 step - 1 |
||
if j mod (1*(10^n)) = 0 and k mod (1*(10^n)) = 0 then j = j/(1*(10^n)) : k = k/(1*(10^n)) |
if j mod (1*(10^n)) = 0 and k mod (1*(10^n)) = 0 then j = j/(1*(10^n)) : k = k/(1*(10^n)): exit for |
||
next n |
next n |
||
l = factor (b3,c) |
|||
if j > k then may = j else may = k |
|||
⚫ | |||
for n = 1 to may |
|||
v = j/l |
|||
s = (k mod n) |
|||
if r = 0 and s = 0 then l = n |
|||
next n |
|||
⚫ | |||
v = j/l |
|||
if x5 <> 0 then print (x5*v)+ u;"/";u ;" = ";((x5*v)+ u)/u else print v;"/";u;" = "; v/u |
if x5 <> 0 then print (x5*v)+ u;"/";u ;" = ";((x5*v)+ u)/u else print v;"/";u;" = "; v/u |
||
print |
|||
f = len(a$) |
|||
print "Option >>> " |
|||
⚫ | |||
call exacto (a$) |
|||
if x5 <> 0 then g7$ = str$(((x5*v)+u)/u) else g7$ = str$(v/u) |
|||
if mid$(a$,1,f) <> mid$(g7$,1,f) then print ">>> error !!!" :j = 1 |
|||
if j = 1 then call multiplo (a$) |
|||
end sub |
end sub |
||
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
|||
function factor (j as integer, k as integer) as integer |
|||
sub multiplo (a$) |
|||
dim as integer |
dim as integer may, n, s, r, l5, j5, k5 |
||
⚫ | |||
dim as string e,f |
|||
⚫ | |||
cls |
|||
⚫ | |||
print "Numero decimal exacto" |
|||
⚫ | |||
⚫ | |||
⚫ | |||
j = 0 |
|||
⚫ | |||
b = len(a$) |
|||
c = instr(a$,".") |
|||
d = b - c |
|||
⚫ | |||
f$ = mid$(a$,c + 1 , d) |
|||
g = val(e$+f$) |
|||
h = 1*(10^d) |
|||
may = 0 'limite |
|||
j = g |
|||
k = h |
|||
if j > k then may = j else may = k |
|||
for n = 9 to 1 |
|||
⚫ | |||
next n |
next n |
||
if j5 > k5 then may = j5 else may = k5 |
|||
⚫ | |||
if j mod n = 0 and k mod n = 0 then l = n :exit for |
|||
⚫ | |||
⚫ | |||
⚫ | |||
next n |
next n |
||
factor = l5 |
|||
u = k/l 'numerador |
|||
end function |
|||
v = j/l 'denominador |
|||
print v;"/";u ;" = "; v / u |
|||
end sub |
|||
end</lang> |
end</lang> |