Heard of the word ‘palindrome’ before? Here’s what it means.
A palindrome is a word, phrase, number, or other sequence of characters which reads the same, when you read it forward or backward.
GET INSTANT HELP FROM EXPERTS!
- Looking for any kind of help on your academic work (essay, assignment, project)?
- Want us to review, proofread or tidy up your work?
- Want a helping hand so that you can focus on the more important tasks?
Hire us as project guide/assistant. Contact us for more information
Here are some examples of palindrome words:
Madam, racecar, malayalam, did, deed, civic, pop, eye, rotor, radar, nun, mom, and dad.
Students who are prepare for English spelling or Quiz competition should know about this word.
Even computer engineering students and those who are learning programming will come across this word, as they have to write the logic to determine if a word is palindrome or not.
Here’s the logic to determine if a number is palindrome, with the help of an example (say 1221).
Temp = i = 1221 before the beginning of the while loop.
Iteration 1:
– temp%10 gives you the rightmost digit (which is 1 here)
– temp/10 removes the rightmost digit and truncates the number to 122.
– now use another variable (revrs) to build the number backwards (the rightmost digit goes to leftmost and so on)
– revrs after first iteration is 1.
Iteration 2:
– temp is 122
– temp%10 gives you the rightmost digit (which is 2 here)
– temp/10 removes the rightmost digit and truncates the number to 12.
– now use another variable (revrs) to build the number backwards (the rightmost digit goes to leftmost and so on)
– revrs after this iteration is (1*10 + 2) = 12.
Iteration 3:
– temp is 12
– temp%10 gives you the rightmost digit (which is 2 here)
– temp/10 removes the rightmost digit and truncates the number to 1.
– now use another variable (revrs) to build the number backwards (the rightmost digit goes to leftmost and so on)
– revrs after this iteration is (12*10 + 2) = 122.
Iteration 4:
– temp is 1.
– temp%10 = 1.
– temp/10 = 0 (which means the while loop will end after this)
– revrs = 122*10 + 1 = 1221.
Now, revrs is the reverse representation of the original number. So that you can now compare i with revrs directly and get the desired result.
StudyMumbai.com is an educational resource for students, parents, and teachers, with special focus on Mumbai. Our staff includes educators with several years of experience. Our mission is to simplify learning and to provide free education. Read more about us.
Leave a Reply
You must be logged in to post a comment.