C Program Check Palindrome Using Recursion



A palindromic number is a number (in some base ) that is the same when written forwards or backwards, i.e., of the form . The first few palindromic numbers are therefore are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101.



  1. //C program to check palindrome using recursion
  2. #include <stdio.h>
  3. #include <math.h>
  4. int rev(int num);
  5. int palin(int num);
  6. int main()
  7. {
  8. int num;
  9. printf("Enter any number: ");
  10. scanf("%d", &num); //taking input from user
  11. if(palin(num) == 1) //calling the recursive function
  12. {
  13. printf("%d is palindrome number.\n", num);
  14. }
  15. else
  16. {
  17. printf("%d is NOT a palindrome number.\n", num);
  18. }
  19. return 0;
  20. }
  21. int palin(int num)
  22. {
  23. if(num == rev(num))
  24. {
  25. return 1;
  26. }
  27. return 0;
  28. }
  29. int rev(int num)
  30. {
  31. //To find no. Of digits
  32. int digit = (int)log10(num);
  33. if(num == 0)
  34. return 0;
  35. return ((num%10 * pow(10, digit)) + rev(num/10));
  36. }

Output
Output!
download android app

Popular C Examples









codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube