Aliquot Sum

 Aliquot Sum explains about the sum of proper divisors of a number excluding that number.

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

proc aliquotSum {n} {
set sum 0;
for {set i 1} {$i <= $n/2} {incr i} {
if {$n % $i == 0} {
# puts $i;
set sum [expr {$sum + $i}];
}
}

return $sum;
}

puts "Aliquot Sum of 30: [aliquotSum 30]";
puts "Aliquot Sum of 31: [aliquotSum 31]";

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