C program to Check Given Number is Palindrome or Not

C program to Check Given Number is Palindrome or Not:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
#include<string.h>
main()
{
   int num,i,cnt=0;
   char str1[10],str2[10];

   printf("Enter a number:");
   scanf("%d",&num);

   //Converting Number to String
   sprintf(str1,"%d",num);

   //Copying the String to Other
   strcpy(str2,str1);

   //Reverse second String
   strrev(str2);
   cnt = strcmp(str1,str2);

   if(cnt == 0)
      printf("%d is a Palindrome",num);
   else
      printf("%d is not a Palindrome",num);
}

OUTPUT:

Enter a number:121
121 is a Palindrome
-------------------------------
Enter a number:157
157 is not a Palindrome

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.