Saturday, June 18, 2011

Palindrome Algorithm


#include<stdio.h>
#include<conio2.h>

int reverse ( int z);

int main()
{
    int B , reversed;
    printf("Input Number : ");
    scanf("%d", &B);
    printf("\n");
    reversed = reverse(B);
    if (reversed == B)
    {
        printf("palindrome");
    }
    else printf("not palindrome");
    getch();
    return 0;
}

int reverse( int z)
{
    int a = 0,b = 0;
    for (a = z; a >0 ; a=a/10)
        {
            b=b*10;
            b+=a%10;
        }
        return b;
}

0 comments: