From 12a62065000ac1f3c3611a130994537b204e866d Mon Sep 17 00:00:00 2001 From: Prateek Chanda Date: Tue, 13 Dec 2016 14:48:53 +0530 Subject: [PATCH] Updating solution for Palindrome --- palindrome.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 palindrome.c diff --git a/palindrome.c b/palindrome.c new file mode 100644 index 00000000..ec82e893 --- /dev/null +++ b/palindrome.c @@ -0,0 +1,26 @@ +#include +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; +}