Maximum difference between adjacent elements of list: Difference between revisions
Content deleted Content added
No edit summary |
→{{header|XPL0}}: Revised for new requirements. |
||
Line 80:
<lang XPL0>real List, Dist, MaxDist;
int I;
[List:= [1., 8., 2., -3., 0., 1., 1., -2.3, 0., 5.5, 8., 6., 2., 9., 11.,
MaxDist:= 0.;
for I:= 0 to
[Dist:= abs(List(I) - List(I+1));
if Dist > MaxDist then
MaxDist:= Dist;
];
for I:= 0 to 17-2 do
[Dist:= abs(List(I) - List(I+1));
if Dist = MaxDist then
[RlOut(0, List(I)); Text(0, ", "); RlOut(0, List(I+1));
Text(0, " ==> "); RlOut(0, MaxDist); CrLf(0);
];
];
]</lang>
{{out}}
<pre>
1, 8
2, 9 ==> 7
10, 3 ==> 7
</pre>
|