Write C program to check palindrome number using recursion


Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Write C program to check palindrome number using recursion


  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. // Function declarations
  5. int reverseNumber(int num);
  6. int isPalindrome(int num);
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12. int num;
  13.  
  14. // Inputting any number from user
  15. printf("Enter any number: ");
  16. scanf("%d", &num);
  17.  
  18. if(isPalindrome(num) == 1)
  19. {
  20. printf("%d is palindrome number.\n", num);
  21. }
  22. else
  23. {
  24. printf("%d is NOT palindrome number.\n", num);
  25. }
  26.  
  27. return 0;
  28. }
  29.  
  30.  
  31. int isPalindrome(int num)
  32. {
  33.  
  34. if(num == reverseNumber(num))
  35. {
  36. return 1;
  37. }
  38.  
  39. return 0;
  40. }
  41.  
  42.  
  43. int reverseNumber(int num)
  44. {
  45. // Finding number of digits in num
  46. int digit = (int)log10(num);
  47.  
  48.  
  49. if(num == 0)
  50. return 0;
  51.  
  52. return ((num%10 * pow(10, digit)) + reverseNumber(num/10));
  53. }
  54.  

Result

C language

     





Related Topics




Popular Posts