Jump to content

Display a linear combination: Difference between revisions

Display a linear combination en FreeBASIC
m (→‎{{header|Phix}}: added syntax colouring the hard way)
(Display a linear combination en FreeBASIC)
Line 665:
{ -1 -2 0 -3 } -> -e(1) - 2*e(2) - 3*e(4)
{ -1 } -> -e(1)
</pre>
 
 
=={{header|FreeBASIC}}==
{{trans|Ring}}
<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</lang>
{{out}}
<pre>
Igual que la entrada de Ring.
</pre>
 
2,169

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.