Created
September 18, 2017 11:51
-
-
Save brianadams121/ee14bae65bb50a9bcf7b1f03b5027905 to your computer and use it in GitHub Desktop.
To check whether a number is palindrome or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int n, reversedInteger = 0, remainder, originalInteger; | |
printf("Enter an integer: "); | |
scanf("%d", &n); | |
originalInteger = n; | |
// reversed integer is stored in variable | |
while( n!=0 ) | |
{ | |
remainder = n%10; | |
reversedInteger = reversedInteger*10 + remainder; | |
n /= 10; | |
} | |
// palindrome if orignalInteger and reversedInteger are equal | |
if (originalInteger == reversedInteger) | |
printf("%d is a palindrome.", originalInteger); | |
else | |
printf("%d is not a palindrome.", originalInteger); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To understand this program,you should possess basic knowledge of C programming and Psiphon For PC.
For example,the output for this program comes to be:
Enter an integer: 1001
1001 is a palindrome.