In this example, we will try to learn about how to check whether the number entered by the user is a palindrome or not while using c programming.
An integer can be called as a palindrome only if the reverse of that number is equal to the original number.
So let us move forward on how to check our see program, and then we will review the output of our program.
Program to Check Palindrome
#include <stdio.h> int main() { int n, reversedInteger = 0, remainder, originalInteger; printf("Enter any integer: "); scanf("%d", &n); originalInteger = n; // reversed integer will be stored in the variable while( n!=0 ) { remainder = n%10; reversedInteger = reversedInteger*10 + remainder; n /= 10; } // palindrome if orignalInteger and reversedInteger are equal to each other if (originalInteger == reversedInteger) printf("%d is a palindrome. \n", originalInteger); else printf("%d is not a palindrome. \n", originalInteger); return 0; }
Output of Code
Enter an integer: 101 101 is a palindrome.
Yeah, today you learned an algorithm on how to covert check whether a number is a palindrome or not. you can also check our post on how to check whether a number is a palindrome or not in java.