1.

How To Check Whether A String Is Palindrome Or Not Using Tcl Script?

Answer»

Code for the above pseudo code.Check if it WORKS!!!!!

gets stdin a

set len [ string LENGTH $a ]

set n [ EXPR $len/2 ]

for { set i 0 } { $i < $n } { incr i 1 } {

set b [ string INDEX $a $i ]

set c [ expr $len – 1 – $i ]

set d [ string index $a $c ]

if {$b != $d} {

puts “not a palindrome”

exit

}

}

puts “Palindrome”

Code for the above pseudo code.Check if it works!!!!!

gets stdin a

set len [ string length $a ]

set n [ expr $len/2 ]

for { set i 0 } { $i < $n } { incr i 1 } {

set b [ string index $a $i ]

set c [ expr $len – 1 – $i ]

set d [ string index $a $c ]

if {$b != $d} {

puts “not a palindrome”

exit

}

}

puts “Palindrome”



Discussion

No Comment Found