Solve equations with substitution method: Difference between revisions

Solve equations with substitution method in various BASIC dialents
(Added Perl)
(Solve equations with substitution method in various BASIC dialents)
Line 14:
 
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<lang BASIC256>arraybase 1
dim firstEquation(3)
firstEquation[1] = 3
firstEquation[2] = 1
firstEquation[3] = -1
dim secondEquation(3)
secondEquation[1] = 2
secondEquation[2] = -3
secondEquation[3] = -19
 
subroutine getCrossingPoint(firstEquation, secondEquation)
x1 = firstEquation[1]
y1 = firstEquation[2]
r1 = firstEquation[3]
x2 = secondEquation[1]
y2 = secondEquation[2]
r2 = secondEquation[3]
dim temp(3)
temp[1] = x1
temp[2] = -y1
temp[3] = r1
resultY = ((temp[1]*r2) - (x2*temp[3])) / ((x2*temp[2]) + (temp[1]*y2))
resultX = (r1 - (y1*resultY)) / x1
print "x = "; resultX
print "y = "; resultY
end subroutine
 
call getCrossingPoint(firstEquation, secondEquation)
end</lang>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
==={{header|FreeBASIC}}===
<lang freebasic>Dim Shared As Integer firstEquation(1 To 3) = { 3, 1, -1}
Dim Shared As Integer secondEquation(1 To 3) = { 2,-3,-19}
 
Sub getCrossingPoint(firstEquation() As Integer, secondEquation() As Integer)
Dim As Integer x1 = firstEquation(1)
Dim As Integer y1 = firstEquation(2)
Dim As Integer r1 = firstEquation(3)
Dim As Integer x2 = secondEquation(1)
Dim As Integer y2 = secondEquation(2)
Dim As Integer r2 = secondEquation(3)
Dim As Integer temp(3)
temp(1) = x1
temp(2) = -y1
temp(3) = r1
Dim As Integer resultY = ((temp(1)* r2) - (x2 * temp(3))) / ((x2 * temp(2)) + (temp(1)*y2))
Dim As Integer resultX = (r1 - (y1*resultY)) / x1
Print "x = "; resultX
Print "y = "; resultY
End Sub
 
getCrossingPoint(firstEquation(), secondEquation())
Sleep</lang>
{{out}}
<pre>x = -2
y = 5</pre>
 
==={{header|QBasic}}===
{{works with|QBasic}}
{{works with|QuickBasic}}
{{trans|FreeBASIC}}
<lang QBasic>DIM firstEquation(3)
firstEquation(1) = 3
firstEquation(2) = 1
firstEquation(3) = -1
DIM secondEquation(3)
secondEquation(1) = 2
secondEquation(2) = -3
secondEquation(3) = -19
 
CALL getCrossingPoint(firstEquation(), secondEquation())
END
 
SUB getCrossingPoint (firstEquation(), secondEquation())
x1 = firstEquation(1)
y1 = firstEquation(2)
r1 = firstEquation(3)
x2 = secondEquation(1)
y2 = secondEquation(2)
r2 = secondEquation(3)
DIM temp(3)
temp(1) = x1
temp(2) = -y1
temp(3) = r1
resultY = ((temp(1) * r2) - (x2 * temp(3))) / ((x2 * temp(2)) + (temp(1) * y2))
resultX = (r1 - (y1 * resultY)) / x1
PRINT "x = "; resultX
PRINT "y = "; resultY
END SUB</lang>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
==={{header|True BASIC}}===
{{works with|QBasic}}
{{trans|QBasic}}
<lang qbasic>DIM firstequation(3)
LET firstequation(1) = 3
LET firstequation(2) = 1
LET firstequation(3) = -1
DIM secondequation(3)
LET secondequation(1) = 2
LET secondequation(2) = -3
LET secondequation(3) = -19
 
SUB getcrossingpoint (firstequation(),secondequation())
LET x1 = firstequation(1)
LET y1 = firstequation(2)
LET r1 = firstequation(3)
LET x2 = secondequation(1)
LET y2 = secondequation(2)
LET r2 = secondequation(3)
 
DIM temp(3)
LET temp(1) = x1
LET temp(2) = -y1
LET temp(3) = r1
 
LET resulty = ((temp(1)*r2)-(x2*temp(3)))/((x2*temp(2))+(temp(1)*y2))
LET resultx = (r1-(y1*resulty))/x1
PRINT "x = "; resultx
PRINT "y = "; resulty
END SUB
 
CALL getcrossingpoint (firstequation(), secondequation())
END</lang>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<lang yabasic>dim firstEquation(3)
firstEquation(1) = 3
firstEquation(2) = 1
firstEquation(3) = -1
dim secondEquation(3)
secondEquation(1) = 2
secondEquation(2) = -3
secondEquation(3) = -19
 
sub getCrossingPoint(firstEquation(), secondEquation())
x1 = firstEquation(1)
y1 = firstEquation(2)
r1 = firstEquation(3)
x2 = secondEquation(1)
y2 = secondEquation(2)
r2 = secondEquation(3)
dim temp(3)
temp(1) = x1
temp(2) = -y1
temp(3) = r1
resultY = ((temp(1)*r2) - (x2*temp(3))) / ((x2*temp(2)) + (temp(1)*y2))
resultX = (r1 - (y1*resultY)) / x1
print "x = ", resultX
print "y = ", resultY
end sub
 
getCrossingPoint(firstEquation(), secondEquation())
end</lang>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
 
2,127

edits