Jump to content

Maximum difference between adjacent elements of list: Difference between revisions

Maximum difference between adjacent elements of list in FreeBASIC
No edit summary
(Maximum difference between adjacent elements of list in FreeBASIC)
Line 418:
idx : 12 values 2.0000000000000000E+000 9.0000000000000000E+000
idx : 15 values 1.0000000000000000E+001 3.0000000000000000E+000 </pre>
 
 
=={{header|FreeBASIC}}==
<lang freebasic>Dim As Single Dist, MaxDist = 0
Dim As Single List(16) => {1., 8., 2., -3., 0., 1., 1., -2.3, 0., 5.5, 8., 6., 2., 9., 11., 10., 3.}
 
Print !"Maximum difference between adjacent elements of list is:"
For i As Integer = 0 To Ubound(List)
Dist = Abs(List(i) - List(i+1))
If Dist > MaxDist Then MaxDist = Dist
Next i
 
For i As Integer = 0 To Ubound(List)
Dist = Abs(List(i) - List(i+1))
If Dist = MaxDist Then Print List(i) & ", " & List(i+1) & " ==> " & MaxDist
Next i</lang>
 
 
=={{header|Go}}==
2,169

edits

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