Skip to content

Instantly share code, notes, and snippets.

@brianadams121
Created September 18, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianadams121/ee14bae65bb50a9bcf7b1f03b5027905 to your computer and use it in GitHub Desktop.
Save brianadams121/ee14bae65bb50a9bcf7b1f03b5027905 to your computer and use it in GitHub Desktop.
To check whether a number is palindrome or not
#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;
}
@brianadams121
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment