Popular Tutorials
Start Learning CCertification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
C Program to Check Whether a Number is Palindrome or Not
In this example, you will learn to check whether the number entered by the user is a palindrome or not.
To understand this example, you should have the knowledge of the following C programming topics:
An integer is a palindrome if the reverse of that number is equal to the original number.
Program to Check Palindrome
#include <stdio.h>
int main() {
int n, reversed = 0, remainder, original;
printf("Enter an integer: ");
scanf("%d", &n);
original = n;
// reversed integer is stored in reversed variable
while (n != 0) {
remainder = n % 10;
reversed = reversed * 10 + remainder;
n /= 10;
}
// palindrome if orignal and reversed are equal
if (original == reversed)
printf("%d is a palindrome.", original);
else
printf("%d is not a palindrome.", original);
return 0;
}
Output
Enter an integer: 1001 1001 is a palindrome.
Here, the user is asked to enter an integer. The number is stored in variable n.
We then assigned this number to another variable orignal. Then, the reverse of n is found and stored in reversed.
If original is equal to reversed, the number entered by the user is a palindrome.
Did you find this article helpful?