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.

#include <stdio.h>
#include <math.h>
 
// Function declarations
int reverseNumber(int num);
int isPalindrome(int num);
 
 
 
int main()
{
    int num;
 
    // Inputting any number from user
    printf("Enter any number: ");
    scanf("%d", &num);
 
    if(isPalindrome(num) == 1)
    {
        printf("%d is palindrome number.\n", num);
    }
    else
    {
        printf("%d is NOT palindrome number.\n", num);
    }
 
    return 0;
}
 
 
int isPalindrome(int num)
{
 
    if(num == reverseNumber(num))
    {
        return 1;
    }
 
    return 0;
}
 
 
int reverseNumber(int num)
{
    // Finding number of digits in num
    int digit = (int)log10(num);
 
 
    if(num == 0)
        return 0;
 
    return ((num%10 * pow(10, digit)) + reverseNumber(num/10));
}

Result

Write C program to check palindrome number using recursion
Write C program to check palindrome number using recursion

Leave a Comment