Display a linear combination: Difference between revisions
m
moved FreeBASIC to section BASIC
(Added various BASIC dialects (Chipmunk Basic, GW-BASIC, MSX Basic, QBasic and Yabasic)) |
m (moved FreeBASIC to section BASIC) |
||
Line 276:
460 next n
470 end</syntaxhighlight>
==={{header|FreeBASIC}}===▼
{{trans|Ring}}▼
<syntaxhighlight lang="freebasic">Dim scalars(1 To 10, 1 To 4) As Integer => {{1, 2, 3}, {0, 1, 2, 3}, _▼
{1, 0, 3, 4}, {1, 2, 0}, {0, 0, 0}, {0}, {1, 1, 1}, {-1, -1, -1}, _▼
{-1, -2, 0, -3}, {-1}}▼
For n As Integer = 1 To Ubound(scalars)▼
Dim As String cadena = ""▼
Dim As Integer scalar▼
For m As Integer = 1 To Ubound(scalars,2)▼
scalar = scalars(n, m)▼
If scalar <> 0 Then▼
If scalar = 1 Then▼
cadena &= "+e" & m▼
Elseif scalar = -1 Then▼
cadena &= "-e" & m▼
Else▼
If scalar > 0 Then▼
cadena &= Chr(43) & scalar & "*e" & m▼
Else▼
cadena &= scalar & "*e" & m▼
End If▼
End If▼
End If ▼
Next m▼
If cadena = "" Then cadena = "0"▼
If Left(cadena, 1) = "+" Then cadena = Right(cadena, Len(cadena)-1)▼
Print cadena▼
Next n▼
Sleep</syntaxhighlight>▼
{{out}}▼
<pre>Same as Ring entry.</pre>
==={{header|GW-BASIC}}===
Line 970 ⟶ 1,003:
[ dup linear-combo "%-14u -> %s\n" printf ] each</syntaxhighlight>
{{out}}
<pre>{ 1 2 3 } -> e(1) + 2*e(2) + 3*e(3)▼
▲{ 1 2 3 } -> e(1) + 2*e(2) + 3*e(3)
{ 0 1 2 3 } -> e(2) + 2*e(3) + 3*e(4)
{ 1 0 3 4 } -> e(1) + 3*e(3) + 4*e(4)
Line 980 ⟶ 1,012:
{ -1 -1 -1 } -> -e(1) - e(2) - e(3)
{ -1 -2 0 -3 } -> -e(1) - 2*e(2) - 3*e(4)
{ -1 } -> -e(1)</pre>
▲=={{header|FreeBASIC}}==
▲{{trans|Ring}}
▲<syntaxhighlight lang="freebasic">Dim scalars(1 To 10, 1 To 4) As Integer => {{1, 2, 3}, {0, 1, 2, 3}, _
▲{1, 0, 3, 4}, {1, 2, 0}, {0, 0, 0}, {0}, {1, 1, 1}, {-1, -1, -1}, _
▲{-1, -2, 0, -3}, {-1}}
▲For n As Integer = 1 To Ubound(scalars)
▲ Dim As String cadena = ""
▲ Dim As Integer scalar
▲ For m As Integer = 1 To Ubound(scalars,2)
▲ scalar = scalars(n, m)
▲ If scalar <> 0 Then
▲ If scalar = 1 Then
▲ cadena &= "+e" & m
▲ Elseif scalar = -1 Then
▲ cadena &= "-e" & m
▲ Else
▲ If scalar > 0 Then
▲ cadena &= Chr(43) & scalar & "*e" & m
▲ Else
▲ cadena &= scalar & "*e" & m
▲ End If
▲ End If
▲ End If
▲ Next m
▲ If cadena = "" Then cadena = "0"
▲ If Left(cadena, 1) = "+" Then cadena = Right(cadena, Len(cadena)-1)
▲ Print cadena
▲Next n
▲Sleep</syntaxhighlight>
▲{{out}}
=={{header|Go}}==
|