Average Mean

 Average Mean explains about the average of a list of numbers.

 Here we are going to write a file named mean.tcl and then we will run it as, tclsh mean.tcl 

# args - list of numbers
#
proc mean {args} {

# Number of elements in the list
set num 0;


# The sum of numbers in the list
set sum 0.0;

foreach number $args {
incr num;
set sum [expr {$sum + $number}];
}

# The mean
return [expr {$sum / $num}];
}

#An example
puts "The mean of 2, 4, 6, 8, 20, 50 and 70 is: [mean 2 4 6 8 20 50 70]";

Happy reading and thank you. Meet you soon.

Comments

Popular posts from this blog

Bash Shell In Linux

Creating An Animation Using A Text Editor

expr command In TCL