|
C Programming Reference >> C Programming Short Notes >> 22/07/07 - 1418 Views - Ratings :
Level - Begineer
This a comparitevely very easy article in which we develop a program to determine wether a number is palindrome or not. In mathematics palindrome is a number which when reverse is a same number. For example 2332 is a palindrome but 2323 is not. You must have clear understanding of this concept. Now what we will be doing is we will be seprating each digits in a number and then reverse them and see if the are exactly same as original. Well we can seprate digits as a string but thier is a more effective and mathematical method for determination which does not depend upon the number of digits in number. In this logic we will seprate each digit one by one using % and / divison arithemetic operators. It should be noted that X % 10 returns the last digit in X while in a integer X/10 truncates X last digit. Also while reversing the digits we will be summing the reversed number to according to thier weight (decimal postion). In this way we will be able to reach correct value of reverse number. Now when this sum is compared to original if they are equal number is a palindrome otherwise not. Only limitation in this program is the range of the variable int or other you used. The program will work only upto that number and not a value larger than that. Source code below is written in C and is implementation of concept above, It produces a list of prime number as output.
Reader Comments -
|
|||||