Thursday, November 11, 2010

C Program to check number is palindrome or not



C Program Code


//Check number is palindrome of not
#include "stdio.h"
#include "conio.h"
void main()
{
int num,rev=0,m,r;
clrscr();
printf("enter any number");
scanf("%d",&num);
m=num;
while(num>0)
{
r=num%10;
rev=rev*10+r;
num=num/10;
}
if(rev==m)
printf("given number is palindrome");
else
printf("given number is not palindrome");
getch();
}

Input/Output


enter any number 121
given number is palindrome

enter any number 423
given number is not palindrome

What is Palindrome No?


when we read a number. If backward read is as same as forward read then number is palindrome.

7 comments:

  1. It helped me in my exam..thanx:-)

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. it helped in lab viva thanks admin

    ReplyDelete
  4. can u please let me know to write a pl/sql program for it

    ReplyDelete
  5. give the explanation for this particular program #include Int main() { Int a[5]={10,20,30,40,50}; Int *ptr=(int *)(&a+1); Printf(“%d %d”,*(a+1),*(ptr-1)); }

    ReplyDelete
  6. good gob but ,Check number is palindrome of not... Check number is palindrome or not? which one ..

    ReplyDelete