Last active
August 9, 2017 10:59
-
-
Save snadahalli/7150315 to your computer and use it in GitHub Desktop.
C Program to check whether a given 5 digit 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
/* C program to check whether a given 5 digit number is palindrome or not | |
* (c) www.c-program-example.com | |
*/ | |
#include<stdio.h> | |
int main() { | |
int num, rem, i, rev = 0, num1, count = 0; | |
printf("Enter a five digit number:\n"); | |
scanf("%d", &num); | |
num1 = num; | |
// reverse the given number | |
while(num > 0) { | |
rem = num % 10; | |
rev = rem + rev * 10; | |
num = num / 10; | |
count++; | |
} | |
if(count == 5) { | |
if(num1 == rev) { // if it's palindrome, reverse & original number will be same | |
printf("The Given Number %d is Palindrome", num1); | |
} else { | |
printf("The Given Number %d is NOT Palindrome",num1); | |
} | |
} else { | |
printf("The given %d number is not a five digit number!",num1); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment