My Tech notes: Palindrome Number Checking for Int C program Functions
Subscribe

Unix Documentation

Free Online Unix Training Materials

Lists many links to free Unix training materials.

Pointers and Arrays Materials

Pointers and Arrays materials Explained for C beginners

C FAQ and General Questions C Interview Questions

Powered By

Free XML Skins for Blogger

Powered by Blogger

Monday, November 3, 2008

Palindrome Number Checking for Int C program Functions

Write a c program to know if given number is palindrome or not?
Well first try to digg out what is palindrome?
A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction. Palindrome example is TENT on either direction characters are same.
The most familiar palindromes, in English at least, are character-by-character: the written characters read the same backwards as forwards. Palindromes may consist of a single word (civic, level, racecar, rotator, Malayalam), or a phrase or sentence ("Was it a rat I saw?", "Wasilla: All I saw", "Mr. Owl ate my metal worm", "Sit on a potato pan, Otis", "Neil, a trap! Sid is part alien!", "Go hang a salami I'm a lasagna hog.", "Satan, oscillate my metallic sonatas", "I roamed under it as a tired nude Maori"). Punctuation, case and spacing are usually ignored, although some (such as "Rats live on no evil star") include the spacing.
That was about palindrome strings or char.
What is importance of palindrome number?

A palindromic number is a number where the digits, with decimal representation usually assumed, are the same read backwards, for example, 58285. They are studied in recreational mathematics where palindromic numbers with special properties are sought. A palindromic prime is a palindromic number that is a prime number.

Now time for C-code;
Its very easy for string or words to know if it is palindrome or not; like

#include
#include
#define size 26
int main(void)
{
char strsrc[size];
char strtmp[size];
printf("\n Enter String:= "); gets(strsrc);
strcpy(strtmp,strsrc);
strrev(strtmp);
if(strcmp(strsrc,strtmp)==0)
printf("\n Entered string \"%s\" ispalindrome",strsrc);
else
printf("\n Entered string \"%s\" is not palindrome",strsrc);
return 0;
}


here is simple program for int palindrome numbers

int main()
{
int i,j,k=0 ;

i = 122223;
printf("i=%d\n",i);
while( i>0 )
{
j = i % 10;
i = i/10;
k = k*10 + j ;
}
return 0;
}

One can customize this for checking given int is numbers are palindrome are not.

No comments:

Post a Comment