Check whether a number is palindrome or not
Sample Output
Check whether a number is palindrome or not. Number: 12321 12321 is palindrome!
Source Code
#include<stdio.h>
int main()
{
int digit, number, numberClone, revNumber = 0;
printf("Check whether a number is palindrome or not.\n\nNumber: ");
scanf("%d", &number);
numberClone = number;
/** Reverse Number */
while(number != 0)
{
digit = (number % 10);
number = (number / 10);
revNumber = (10 * revNumber) + digit;
}
/** Reverse number end */
if(numberClone == revNumber)
{
printf("\n%d is palindrome!\n\n", numberClone);
}
else
{
printf("\n%d is not palindrome.\n\n", numberClone);
}
return 0;
}
Sample Output
Check whether a number is palindrome or not. Number: 45674 45674 is not palindrome.
No comments:
Post a Comment