Created
September 19, 2017 10:17
-
-
Save saisankargochhayat/45ccf4f220aa38d0c3504f4876226c7f to your computer and use it in GitHub Desktop.
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> | |
#include <math.h> | |
int num(int n); | |
int main() | |
{ | |
int i; | |
scanf("%d",&i); | |
if(num(i)==i) | |
{ | |
printf("Palindrome\n"); | |
} | |
else | |
{ | |
printf("Not a palindrome\n"); | |
} | |
} | |
int num(int n) | |
{ | |
//Finds total number of digits | |
int digit = (int)log10(n); | |
// Base condition | |
if(n == 0) | |
return 0; | |
return ((n%10 * pow(10, digit)) + num(n/10)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't use pointers to pass values unless necessary. Pass the copy of values. And don't use recursion unless necessary.