Jump to content

Averages/Arithmetic mean: Difference between revisions

(Added solution for EDSAC)
Line 857:
(/ (loop for i in list sum i)
(length list))))</syntaxhighlight>
 
=={{header|Craft Basic}}==
<syntaxhighlight lang="basic">'version 1: using an array
 
dim a[3, 1, 4, 1, 5, 9]
 
arraysize s, a
 
for i = 0 to s - 1
 
let t = t + a[i]
 
next i
 
print t / s
 
end</syntaxhighlight>
 
<syntaxhighlight lang="basic">'version 2: without using an array
 
input "how many numbers to average? ", n
 
for i = 1 to n
 
input "enter a number: ", s
let a = a + s
 
next i
 
print "average: ", a / n
 
end</syntaxhighlight>
 
=={{header|Crystal}}==
305

edits

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