Home

A program to find whether given number is PALINDROME (or) NOT

C Programming Language 029

The following code shows how to write a program to find whether given number is PALINDROME (or) NOT.

Program

#include <stdio.h>

void main()
{
    int n, rev, temp, sum = 0;
    printf("Enter a value: ");
    scanf("%d", &n);

    temp = n;
    while (n > 0)
    {
        rev = n % 10;
        sum = rev + 10 * sum;
        n = n / 10;
    }

    if (sum == temp)
    {
        printf("It is palindrome");
    }
    else
    {
        printf("It is not a palindrome");
    }

    printf("\n");
}

Result

Enter a value: 151
It is palindrome


Last Updated on

Next Post: Rules vs Guidelines →

Comments