C Program To Check Palindrome

The following is a C Program to check if Given number is a Palindrome on screen after taking input from user. Let's get started.

C Program To Check Palindrome
C Program To Check Palindrome

Overview:


Commands

scanf() function is used to obtain input and printf() function is used to print the string on the screen.
while() loop is used as test condition

Program

#include<stdio.h>
#include<conio.h>
int main()
{
    int n,reversedint=0, remainder,mainint;
    clrscr();
    printf("Enter an integer: ");
    scanf("%d",&n);
    mainint= n;
    /*reversed integer is stored in variable*/
    while(n!=0)
    {
        remainder=n%10;
        reversedint= reversedint*10+remainder;
        n/=10;
    }
    /*palindrome if mainint and reversedint are equal*/
    if(mainint==reversedint)
        printf("%d is a palindrome.",mainint);
    else
        printf("%d is not a palindrome.",mainint);
    getch();
}


Output

Palindrome Output
Palindrome Output


All programs compiled in this post are compiled in AnDOSBox.

Books I Prefer:






I hope this article was helpful to understand C Program to check if Given number is a Palindrome! Comment below, if you've got any question. Head back soon for another interesting article on C Programming.