Averages/Median: Difference between revisions
Content deleted Content added
Basicgames (talk | contribs) |
Initial FutureBasic task solution added |
||
Line 3,135:
Median for first 9 elements : 4.4
</pre>
=={{header|FutureBasic}}==
FB has native averaging functions.
<syntaxhighlight lang="futurebasic">
local fn MedianAverage( arguments as CFArrayRef ) as CFStringRef
ExpressionRef expRef = fn ExpressionForFunction( @"median:", @[fn ExpressionForConstantValue( arguments )] )
CFNumberRef result = fn ExpressionValueWithObject( expRef, NULL, NULL )
CFStringRef median = fn NumberStringValue( result )
end fn = median
print fn MedianAverage( @[@1, @9, @2] ) // 2
print fn MedianAverage( @[@1, @9, @2, @4] ) // 3
print fn MedianAverage( @[@5.961475, @2.025856, @7.262835, @1.814272, @2.281911, @4.854716] ) // 3.5683135
print fn MedianAverage( @[@4.1, @5.6, @7.2, @1.7, @9.3, @4.4, @3.2] ) // 4.4
print fn MedianAverage( @[@40.12, @860.77, @960.29, @920.13] ) // 890.45
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
2
3
3.5683135
4.4
890.45
</pre>
=={{header|GAP}}==
|