How to Check for Palindrome number in an Decimal Array in C

#include <stdio.h>

char checkpalindrome(int a)
{
    int reminder;
    int reverse = 0;
    int result = 0;
    int orgnum = a;
    while(a)
    {
        reminder = a % 10;
        a = a / 10;
        reverse = (reverse * 10) + reminder;
        //printf("%d\n",reverse);
    }
    if(reverse == orgnum)
    {
        printf("Valid Palindrome - %d = %d\n", reverse,orgnum);
        result = 1;
    }
    else
    {
        printf("(reverse) %d != %d (original)\n", reverse,orgnum);
    }
    return result;
}

int main(void) {
    // your code goes here
    int x[3] = {121,15151,1022};
    checkpalindrome(x[0]);
    checkpalindrome(x[1]);
    checkpalindrome(x[2]);

    return 0;
}

Related Post:


Removing Space from Given String & Different Methods to Count Number of Ones in Given Value

Booting Sequence for Boot Process in Linux

How to count number of 1 or set bits in a given number

What is Segmentation fault ?

How to Access Private Data Members in C++ without using friend function

Process Vs Thread 

How to Add Two Numbers Without Using + Operator in C 

Overview of Function Pointer in C with Example - What is function pointer & how to use it

How to Fork child process with waitpid & execl in linux with c example code

Share on Google Plus

About Unknown

"I am Kapil Thakar, an Embedded Engineer cum Blogger wants to learn new things. I love to share my knowledge solutions to the problems. Interested in Blogging, Creative-Writing, SEO, Website Creation, Video Making, Editing, Affiliation Programs, Online Making Money."
    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment

Related Posts Plugin for WordPress, Blogger...