Skip to content

Instantly share code, notes, and snippets.

@saisankargochhayat
Created September 19, 2017 10:17
Show Gist options
  • Save saisankargochhayat/45ccf4f220aa38d0c3504f4876226c7f to your computer and use it in GitHub Desktop.
Save saisankargochhayat/45ccf4f220aa38d0c3504f4876226c7f to your computer and use it in GitHub Desktop.
#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));
}
@saisankargochhayat
Copy link
Author

Don't use pointers to pass values unless necessary. Pass the copy of values. And don't use recursion unless necessary.

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