You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

29 lines
504 B

#!/usr/bin/env tclsh
# TCL version of a Prime Number Finder
# haplo@mindstab.net
if { $argc == 0 } {
puts "Useage: primes.tcl \[Max Num\]"
exit
}
set MAX [lindex $argv 0]
if { $MAX < 1 } {
puts "Max Num must be greater than 1"
exit
}
for { set cnt 3} {$cnt <= $MAX} {incr cnt 2} {
set max_test [expr sqrt($cnt)]
set isPrime 1
for {set test 3} {$test <= $max_test} {incr test 2} {
if { [expr $cnt % $test] == 0 } {
set isPrime 0;
break
}
}
if { $isPrime == 1 } {
puts $cnt
}
}