Write a C program to check number is palindrome or not using Recursion. Here’s simple program to check number is palindrome or not using Recursion in C Programming Language.
Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.
The C programming language supports recursion, i.e., a function to call itself. But while using recursion, programmers need to be careful to define an exit condition from the function, otherwise it will go into an infinite loop.
Recursive functions are very useful to solve many mathematical problems, such as calculating the factorial of a number, generating Fibonacci series, etc.
Here is the source code of the C program to check number is palindrome or not using Recursion. The C Program is successfully compiled and run on a Windows system. The program output is also shown below.
SOURCE CODE : :
/* C program to check number is palindrome or not using Recursion */
#include<stdio.h>
int checkPalindrome(int);
int main(){
int num,sum;
printf("Enter any number :: ");
scanf("%d",&num);
sum = checkPalindrome(num);
if(num==sum)
printf("\n%d is a palindrome\n",num);
else
printf("\n%d is not a palindrome\n",num);
return 0;
}
int checkPalindrome(int num){
static int sum=0,r;
if(num!=0){
r=num%10;
sum=sum*10+r;
checkPalindrome(num/10);
}
return sum;
}
Output : :
/* C program to check number is palindrome or not using Recursion */
Enter any number :: 1234321
1234321 is a palindrome
Process returned 0
Above is the source code for C program to check number is palindrome or not using Recursion which is successfully compiled and run on Windows System.The Output of the program is shown above .
Recursion : :
Here is the source code of the C program to check number is palindrome or not using Recursion. The C Program is successfully compiled and run on a Windows system. The program output is also shown below.
SOURCE CODE : :
Output : :
Above is the source code for C program to check number is palindrome or not using Recursion which is successfully compiled and run on Windows System.The Output of the program is shown above .
need an explanation for this answer? contact us directly to get an explanation for this answer