Dremendo Tag Line

Input a number and check it is a palindrome number or not using while loop in C

while Loop - Question 14

In this question, we will see how to input a number and check if it is a palindrome number or not in C programming using while loop. To know more about while loop click on the while loop lesson.

Q14) Write a program in C to input a number and check if it is a palindrome number or not using while loop.

Palindrome numbers are such numbers whose reverse is same as the original number. Example, 121, 14541, 22 etc.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int n,d,on,rev=0;

    printf("Enter any number ");
    scanf("%d",&n);
    on=n;			// storing the original number

    while(n>0)
    {
        d=n%10;
        rev=(rev*10)+d;		// reverse the number
        n=n/10;
    }

    if(on==rev)
    {
        printf("Palindrome Number");
    }
    else
    {
        printf("Not Palindrome Number");
    }
    return 0;
}

Output

Enter any number 14541
Palindrome Number
video-poster