#!/usr/bin/tclsh
puts "Enter the number: "
gets stdin input
proc checkPrime {number} {
set flag 0
set part [expr int(sqrt($number))]
for {set i 2} {$i <= $part} {incr i} {
if {[expr $number % $i] == 0} {
set flag 1
break
}
}
return $flag
}
if {[checkPrime $input] == 1} {
puts "$input is not a prime number"
} elseif { [ lindex $input 0 ] == 0 } {
set in $input [ lindex 1 -1]
if {[checkPrime $in]} {
}
} else {
puts "$input is a prime number"
}
Output:
Enter the number:
23
23 is a prime number
Enter the number:
21
21 is not a prime number
Comments
Post a Comment