Write a program to check given number is palindrome number or not

// Write a program to check given number is palindrome number or not
// Ex: 4 -> Palindrome, 12321 -> Palindrome, 2342 -> Not Palindrome

#include
int main(){
    int n;
    printf("Enter a positive integer:");
    scanf("%d",&n); // input from user
    while(n<0){ printf("Please enter positive integer only:"); scanf("%d",&n); } int rev=0; int m = n; while(n>0){
         rev = rev*10+n%10; // finding reverse of given number
         n = n/10;
    }
    if(m==rev){ // checking if palindrome
         printf("%d is a palindrome number",m);
    }
    else{
         printf("%d is not palindrome number",m);
    }
    getch();
}

No comments:

Post a Comment