Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
|
|
@ -0,0 +1,22 @@
|
|||
import ballerina/io;
|
||||
|
||||
function average(decimal[] a) returns decimal {
|
||||
decimal sum = 0;
|
||||
if a.length() == 0 { return 0d; }
|
||||
foreach decimal i in a { sum += i; }
|
||||
return <decimal>sum / a.length();
|
||||
}
|
||||
|
||||
public function main() {
|
||||
// fixed length array
|
||||
decimal[6] a = [1, 2, 3, 4, 5, 6];
|
||||
io:println(decimal:avg(...a));
|
||||
|
||||
// variable length array
|
||||
decimal[] b = a;
|
||||
io:println(average(b));
|
||||
|
||||
// empty variable length array
|
||||
decimal[] c = [];
|
||||
io:println(average(c));
|
||||
}
|
||||
|
|
@ -1,9 +1,6 @@
|
|||
proc mean . f[] r .
|
||||
for i = 1 to len f[]
|
||||
s += f[i]
|
||||
.
|
||||
r = s / len f[]
|
||||
func mean &f[] .
|
||||
for i = 1 to len f[] : s += f[i]
|
||||
return s / len f[]
|
||||
.
|
||||
f[] = [ 1 2 3 4 5 6 7 8 ]
|
||||
mean f[] r
|
||||
print r
|
||||
print mean f[]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue