tcl programs for some maths exper

######factorial##############
gets stdin n 

proc fact {n} {
    set f 1
    for {set i 1} {$i<=$n} {incr i} {
       set f [expr {$f * $i}]
    }
    puts "factorial of $n is $f"
 }
fact $n
###################sum of n numbers###############
gets stdin m
proc sum1 {m} {
set s 0
for {set i 1} {$i<=$m} {incr i} {
set s [expr $s+$i]
  
}
puts "sum of numbers from 1 to $m is $s"
 }
sum1 $m
####################factors of a numbers##########
gets stdin d
proc factor {d} {
for {set i $d} {$i>1} {incr i -1} {
if {$d%$i == 0} {
puts "factors are $i"
}
}
}
factor $d
######sum using while#############
gets stdin a
proc sum {a} {
set s 0
set i 1
while {$i<=$a} {
set s [expr $s+$i]
incr i
}
puts "sum of numbers from 1 to $a using while $s "
}
sum $a