Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
puts "Hello World!"
proc try {a {b 3}} {
puts "in Try, the a is $a"
set a [expr $b * 2]
return "The a is $a and b is $b"
}
set msg [try 4]
# set msg "I am the one!"
puts $msg
set A(a) "V1"
set A(b) "V2"
set A(c) "V3"
foreach {k v} [array get A] {
puts "key : $k ; val : $v"
}
puts [array names A]
# puts [keys $A]
puts [array get A]
puts [array size A]
array set A1 {aa 0 bb 1 cc 20}
foreach {k v} [array get A1] {
puts "key : $k ; val : $v"
}
puts "Truth Table based Gate Level Simulator"
# boolean equation provided as input and displays it
puts -nonewline "Enter a boolean expression: "
flush stdout
set exp [gets stdin]
puts $exp
set variables [lsort -unique [regexp -inline -all {\$\w+} $exp]]
set length [llength $variables]
# differentiating among the variables as hey can be present number of times
set command [list format [string repeat "%s\t" $length]%s]
append command " {*}\[[list subst $variables]\] \[[list expr $exp]\]"
set command "puts \[$command\]"
#calculates the value for each input combinations
foreach v [lreverse $variables] {
set command [list foreach [string range $v 1 end] {0 1} $command]
}
#displays the output
puts " "
puts [join $variables \t]\tResult
apply [list {} $command]
#!/usr/bin/tclsh
for {set x 2} {$x<100} {incr x} {
set flag 1
for {set i 2} {$i<$x} {incr i} {
set y [expr $x % $i]
if {$y == 0} {
#puts "$x: not a prime no"
set flag 0
break
}
}
if {$flag ==1} {
puts "$x: prime no"
}
}