Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 palindrome
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
scorpion1087




PostPosted: Thu Oct 30, 2003 4:27 pm   Post subject: palindrome

how do you check if a palindrome is true

eg
mom will have 1 check because the m's cancel and whatever is in the middle is left over.

my email is scorpion1087@hotmail.com

ps how do you create a palindrome
Sponsor
Sponsor
Sponsor
sponsor
Blade




PostPosted: Thu Oct 30, 2003 5:16 pm   Post subject: (No subject)

umm... you'd have to use a reversed for loop and use two variables.... thats the easiest way
ex:
code:
var word1,word2:string(30):=""
word:="mom"
for decreasing i:1..length(word1)
  word2+=word1(i)
end for
if (word1 = word2) then
  %is a palindrome
end if


thats just one way, theres more but i think thats the easiest...
Andy




PostPosted: Thu Oct 30, 2003 5:31 pm   Post subject: (No subject)

you could also do this
code:

var word :string:="mom"
for i:1..length(word) div 2
    for decreasing j: length(word)..length(word) div 2
        if word(i) not= word(j)
            put "no"
            return
        end if
    end for
end for

better than blade's method cuz u dont need a new var Laughing
Blade




PostPosted: Sun Nov 02, 2003 1:41 am   Post subject: (No subject)

Blade wrote:
thats just one way, theres more but i think thats the easiest...


duh - didnt say it was the best
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: