0
1.6kviews
Write a program to check whether the given number is palindrome or not. i.e if no is 12421 it is palindrome.
1 Answer
0
46views
  • Palindrome can be a word, phrase, or sequence that reads the same backwards as forwards.

  • Some palindrome strings examples are "dad", "radar", "madam" etc.

  • Palindrome program works as follows:- at first we copy the entered string into a new string, and then we reverse the new string and then compares it with original string.

  • If both of them have same sequence of characters i.e. they are identical then the entered string is a palindrome otherwise not.

Program:

#include<stdio.h>
int main(){
int num, r, sum=0, temp;
printf("Enter a number: ");
scanf("%d",&num);

temp=num;

while(num){
        r=num%10;
        num=num/10;
        sum=sum*10+r;
    }

if(temp==sum)
        printf("%d is a palindrome.",temp);

else
        printf("%d is not a palindrome.",temp);

return 0;
}

Output:

Enter a number: 12421

12421 is a palindrome.

Please log in to add an answer.