Greatest element of a list: Difference between revisions

Content deleted Content added
→‎{{header|Zig}}: format, make example generic, annotate versions
Miks1965 (talk | contribs)
PascalABC.NET
 
(4 intermediate revisions by 4 users not shown)
Line 998:
160 PRINT "THE MAXIMUM VALUE WAS ";C;" AT INDEX ";I;"."
170 END</syntaxhighlight>
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">1000 DEF FINDMAX(REF ARR)
1010 LET MX=ARR(LBOUND(ARR))
1020 FOR I=LBOUND(ARR)+1 TO UBOUND(ARR)
1030 LET MX=MAX(MX,ARR(I))
1040 NEXT
1050 LET FINDMAX=MX
1060 END DEF</syntaxhighlight>
 
==={{header|MSX Basic}}===
Line 1,031 ⟶ 1,040:
130 PRINT "The maximum value was "; c; " at index "; i; "."
140 END</syntaxhighlight>
 
==={{header|SmallBASIC}}===
<syntaxhighlight lang="eulerqbasic">
list = [1,1234,62,234,12,34,6]
print max(list)
</syntaxhighlight>
 
=={{header|Batch File}}==
Line 1,847 ⟶ 1,862:
=={{header|Euler}}==
Euler allows hetrogenous lists, the <code>real</code> operator converts boolean and symbol (short character strings) to a number (leaving numeric values unchanged) and the <code>isu</code> operator tests whether its operand is <code>undefined</code> or not.
'''begin''' '''new''' greatest;
<syntaxhighlight lang="euler">
begin new greatest &lt;- ` '''formal''' ls;
'''begin''' '''new''' L; '''new''' i; '''new''' result; '''label''' iLoop;
greatest <- ` formal ls;
begin new L; new i; new result; label iLoop&lt;- ls;
L result <&lt;- ls'''undefined''';
result <i &lt;- undefined0;
iLoop: '''if''' [ i &lt;- i + 1 ] &lt;= '''length''' <-L 0;'''then''' '''begin'''
iLoop: if [ i <- i + 1 ] <= length '''if''' '''isu''' result '''or''' '''real''' L[ i ] &gt; then'''real''' beginresult
if isu result or real'''then''' result &lt;- L[ i ] >'''else''' real result0;
'''goto''' then result <- L[ i ] else 0;iLoop
'''end''' '''else''' goto iLoop0;
end else 0;result
result'''end'''
end&apos;;
'''out''' greatest( ( '''false''', 99.0, -271, "b", 3, 4 ) ';)
'''end''' $
out greatest( ( false, 99.0, -271, "b", 3, 4 ) )
end $
</syntaxhighlight>
 
=={{header|Euler Math Toolbox}}==
Line 2,482 ⟶ 2,495:
4
</pre>
 
=={{header|IS-BASIC}}==
<syntaxhighlight lang="is-basic">1000 DEF FINDMAX(REF ARR)
1010 LET MX=ARR(LBOUND(ARR))
1020 FOR I=LBOUND(ARR)+1 TO UBOUND(ARR)
1030 LET MX=MAX(MX,ARR(I))
1040 NEXT
1050 LET FINDMAX=MX
1060 END DEF</syntaxhighlight>
 
=={{header|J}}==
Line 3,819 ⟶ 3,823:
FindMaxInt 999999 @ 691620
FindMaxFlt 999999.0265 @ 14824</pre>
 
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
##
var values := Lst(1,7,4,6,3,5,2,6);
values.Max.Print;
</syntaxhighlight>
 
=={{header|Perl}}==
Line 4,756 ⟶ 4,767:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var max = Fn.new { |a| a.reduce { |m, x| (x > m) ? x : m } }
 
var a = [42, 7, -5, 11.7, 58, 22.31, 59, -18]