How do you check whether a string is palindrome or not using TCL script?
Answer Posted / suraj
set str "madam" # The palindrome string
set lstr [ split $str "" ]
set len [ llength $lstr]
set i 0
set j [ expr $len - 1 ]
while {1} {
if { $j<= $i } {
puts "its palindrome"
break
} else {
set a [ lindex $lstr $i ]
set b [ lindex $lstr $j ]
if { $a != $b } {
puts "its not palindrome"
break
} else {
incr i
incr j -1
}
}
}
Is This Answer Correct ? | 4 Yes | 3 No |
Post New Answer View All Answers