The Maximum Of Numbers

 The maximum of a list of numbers is the largest number among that numbers.

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

#max.tcl
#
proc max {args} {

set max [lindex $args 0];

foreach num $args {
if {$num > $max} {
set max $num;
}
}

return $max;
}

#Examples
#
puts "The maximum out of 5, 18 and 200: [max 5 18 200]";
puts "The maximum out of 201, 5, 18 and 200: [max 201 5 18 200]";
puts "The maximum out of 5, 18, 200 and 300: [max 5 18 200 300]";

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