Example: #1 - Check the number is a Palindrome
Check the number is a Palindrome using a divide and modulus approach
C Input Screen
#include<stdio.h>
int main(int argc, const char * argv[])
{
int originalNumber = 12321;
int remainder, reverseNumber = 0;
int temp = originalNumber;
while (temp > 0) {
remainder = temp % 10;
reverseNumber = (reverseNumber * 10) + remainder;
temp = temp / 10;
}
if (originalNumber == reverseNumber) {
printf("The given number is Palindrome");
} else {
printf("The given number is NOT a Palindrome");
}
}
C Output Screen
The given number is Palindrome